js怎么根据日期时间转换时间戳

如题所述

// 获取当前时间戳(以s为单位)
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
//当前时间戳为:timestamp
console.log("当前时间戳为:" + timestamp);



Date.parse()函数用于分析一个包含日期的字符串,并返回该日期与 1970 年 1 月 1 日午夜之间相差的毫秒数。

温馨提示:答案为网友推荐,仅供参考
相似回答