欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > js/javascript获取时间戳的5种方法

js/javascript获取时间戳的5种方法

2024/10/26 15:26:45 来源:https://blog.csdn.net/hexadecimal_001/article/details/139664529  浏览:    关键词:js/javascript获取时间戳的5种方法

1.获取时间戳精确到秒,13位

const timestamp = Date.parse(new Date());
console.log(timestamp);//输出 1591669256000   13位

2.获取时间戳精确到毫秒,13位

const timestamp = Math.round(new Date());
console.log(timestamp);//输出 1591669961203   13位

3.获取时间戳精确到毫秒,13位

const timestamp = (new Date()).valueOf();
console.log(timestamp);//输出 1591670037603   13位

4.获取时间戳精确到毫秒,13位

const timestamp = new Date().getTime();
console.log(timestamp);//输出 1591670068833   13位

5.获取时间戳精确到毫秒,13位

const timestamp = +new Date();
console.log(timestamp);//输出 1591670099066   13位

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。

+new Date()

 new Date().getTime()

 Date.now()

时间戳主要用于清理缓存,大多数用于版本更新;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com