Home > Web Front-end > JS Tutorial > JavaScript code to compare time size_time and date

JavaScript code to compare time size_time and date

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:28:41
Original
1471 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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template