Instance analysis of comparison of two timestamps in JS
var start=1491789600000;//2017-4-10 10:00 var end=1494381600000;//2017-5-10 10:00 var utc=end-start; 天:utc/(24*60*60*1000); 小时:utc/(60*60*1000); 分:utc/(60*1000);
JavaScript Get the currentTime stamp:
First method:
var timestamp = Date.parse(new Date());
Result:
1280977330000
Second method:
var timestamp = (new Date()).valueOf();
Result:
1280977330748
Third method:
##
var timestamp=new Date().getTime();
Result:
1280977330748
第一种:获取的时间戳是把毫秒改成000显示,
第二种和第三种是获取了当前毫秒的时间戳。
转换成毫秒之即可比较时间的大小
The above is the detailed content of Example analysis of comparing two timestamps in JS. For more information, please follow other related articles on the PHP Chinese website!