如何在javascript中将普通日期2012.08.10转换为unix时间戳?
小提琴:http://jsfiddle.net/J2pWj/
我在这里看到过很多把它转换成PHP、Ruby等的帖子。但我需要在JS中执行此操作。
发布于 2012-08-10 06:53:02
new Date('2012.08.10').getTime() / 1000发布于 2015-02-24 05:23:46
parseInt((new Date('2012.08.10').getTime() / 1000).toFixed(0))重要的是要添加toFixed(0),以便在除以1000时删除任何小数,以便将毫秒转换为秒。
.getTime()函数以毫秒为单位返回时间戳,但真正的unix时间戳始终以秒为单位。
发布于 2017-06-19 23:19:38
var d = '2016-01-01T00:00:00.000Z';
console.log(new Date(d).valueOf()); // returns the number of milliseconds since the epoch
https://stackoverflow.com/questions/11893083
复制相似问题