js date comparison, time and milliseconds in js are converted to each other

Compare the size of two dates

 

var a = Date.UTC(year, month, day, hour, minute, second);
var b = Date.UTC(year, month, day, hour, minute, second);
if (a>b) {
    alert(" a>b");
} else if (a<b) {
    alert("a<b");
} else {
    alert("a=b");
}

 

Convert time to milliseconds in js

 

js convert millisecond time to datetime

 
 
var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //Get the number of milliseconds  
 
 
//Times that are not in the above format need to be converted
 
 
   //starttime ='2012-12-25 20:17:24';
    starttime = starttime.replace(new RegExp("-","gm"),"/");
    var starttimeHaoMiao = (new Date(starttime)).getTime(); //Get the number of milliseconds
 
 
[2] Convert milliseconds to time
 
 
var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //Get the number of milliseconds  
var newTime = new Date(oldTime); //get the normal time 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326743471&siteId=291194637