中国标准时间和时间戳互转

您所在的位置:网站首页 108个福字图片能打印出来吗怎么弄 中国标准时间和时间戳互转

中国标准时间和时间戳互转

2024-07-16 00:41| 来源: 网络整理| 查看: 265

1、中国标准时间转换成时间戳 

new Date().getTime()

new Date() // Wed Jan 12 2022 11:14:50 GMT+0800 (中国标准时间) new Date().getTime() // 1641957294080

2、时间戳转换成中国标准时间

new Date(start)

举例,我想获取当前中国标准时间 Wed Jan 12 2022 11:17:32 GMT+0800 (中国标准时间),取上个月这一天的时间。那么就需要先转成时间戳,再减去一个月的时间,再转成中国标准时间就可以了。

let start = new Date().getTime() - 3600 * 1000 * 24 * 30; console.log(start) //1639365452201 new Date(start); console.log(start)//Mon Dec 13 2021 11:17:32 GMT+0800 (中国标准时间)

3.至于时间格式,后端经常会要我们转成标准的年月日时分秒格式,具体的转换方法,请看我另一篇文章,有详细讲述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3