首页 > Web开发 > 详细

js格式化 Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间) 及相互转化

时间:2019-08-23 16:28:48      阅读:578      评论:0      收藏:0      [点我收藏+]
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, '/')))
          }
    },

转载 https://blog.csdn.net/qq_32963841/article/details/89243617

js格式化 Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间) 及相互转化

原文:https://www.cnblogs.com/sunBinary/p/11400689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!