JavaScript 比较时间大小的代码_时间日期

WBOY
Release: 2016-05-16 18:28:41
Original
1337 people have browsed it

例如: Date.parse( "2000-01-01" ) IE and Mozilla浏览器: "NaN"。那么我们一般在Web页面上显示的时 间 就不能直接转换。需要做处理。
可以直接转换的格式"01/01/2000","2000/01/01"

复制代码代码如下:

//定义正则表达式,因为jS对只能替换一个
//转换为 "2000/01/01"
var regS = new RegExp("-","gi");
var date1=document.getElementById("begindate");
var date2=document.getElementById("enddate");
date1=date1.replace(regS,"/");

date2=date2.replace(regS,"/");
var bd =new Date(Date.parse(date1));
var ed =new Date(Date.parse(date2));

bd,ed是时间对象,可以直接比较大小了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!