Home > Web Front-end > JS Tutorial > body text

JavaScript code to compare time size_time and date

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

For example: Date.parse( "2000-01-01" ) IE and Mozilla browsers: "NaN". Then the time we usually display on the Web page cannot be converted directly. Need to be processed.
Formats that can be directly converted "01/01/2000", "2000/01/01"

Copy code Code As follows:

//Define the regular expression, because jS can only replace one
//Convert to "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 are time objects and can be compared directly.
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
Popular Tutorials
More>
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!