将标准时间时间转化为时间戳,将时间戳转化为标准时间

将‘2017-2-1’转化为时间戳  new Date('2017-2-1').getTime()

在‘2017-2-1’的基础上加一天    先转化时间戳 new Date('2017-2-1').getTime(),在此基础上加24*3600*1000

再将时间戳转化为想要的格式  new Date(时间戳数字类型).getFullYear()

将时间戳转化为标准时间 new Date(时间戳)'Sat Oct 10 2020 16:10:33 GMT+0800 (中国标准时间)'

再转化为时间字符  new Date(时间戳) .toLocaleString('chinese', {hour12: false})

补充:

toLocaleString把数组转换为本地字符串。   首先调用每个数组元素的 toLocaleString() 方法,然后使用地区特定的分隔符把生成的字符串连接起来,形成一个字符串

posted @ 2020-05-26 18:26  star-meteor  阅读(7040)  评论(0)    收藏  举报