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

JavaScript code to compare time size_time and date

WBOY
WBOYOriginal
2016-05-16 18:28:411448browse

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.
Statement:
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