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

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐