js格式化 GMT+0800 (中国标准时间)
时间:2019-12-12 16:27:52
收藏:0
阅读:1309
1. Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间) 转换为 2019-03-07 12:00:00
const d = new Date(Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间)) const resDate = d.getFullYear() + ‘-‘ + this.p((d.getMonth() + 1)) + ‘-‘ + this.p(d.getDate()) const resTime = this.p(d.getHours()) + ‘:‘ + this.p(d.getMinutes()) + ‘:‘ + this.p(d.getSeconds())
p为不够10添加0的函数
p(s) { return s < 10 ? ‘0‘ + s : s },
2.2019-03-07 12:00:00转换为 Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间)
parserDate(date) { var t = Date.parse(date) if (!isNaN(t)) { return new Date(Date.parse(date.replace(/-/g, ‘/‘))) } },
3.时间转时间戳
将Thu Sep 20 2018 16:47:52 GMT+0800 (中国标准时间)
转换为1537433272051
console.log(Date.parse(new Date())) console.log(new Date().getTime())
将"2018-09-20 16:50:48"
转换为1537433448000
var timeDate = "2018-09-20 16:50:48"; var Time = new Date(timeDate); var timestemp = Time.getTime(); console.log(timestemp)
原文:https://www.cnblogs.com/ll15888/p/12029866.html
评论(0)