Example analysis of comparing two timestamps in JS

黄舟
Release: 2017-10-24 09:36:01
Original
2237 people have browsed it

Instance analysis of comparison of two timestamps in JS

Copy after login

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);
Copy after login

JavaScript Get the currentTime stamp:
First method:

var timestamp = Date.parse(new Date());
Copy after login

Result:

1280977330000
Copy after login

Second method:

var timestamp = (new Date()).valueOf();
Copy after login

Result:

1280977330748
Copy after login
Copy after login

Third method:
##

var timestamp=new Date().getTime();
Copy after login

Result:

1280977330748
Copy after login
Copy after login

第一种:获取的时间戳是把毫秒改成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!

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 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!