前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cssjshtml js yyMMdd格式字符串与时间互转

cssjshtml js yyMMdd格式字符串与时间互转

作者头像
葫芦
发布2019-04-17 16:27:27
2K0
发布2019-04-17 16:27:27
举报
文章被收录于专栏:葫芦葫芦

1.'20190222' -> Fri Feb 22 2019 00:00:00 GMT+0800 (中国标准时间),并加一天。

先在字符串中加入'/',通过new Date转换,转换后为Date对象可以做时间上的加减。

代码语言:javascript
复制
let date = new Date(event.name.slice(0, 4) + '/' + event.name.slice(4, 6) + '/' +event.name.slice(6, 8))
let starttime = date
let endtime = new Date(date.getTime() + 24 * 60 * 60 * 1000)

2.Fri Feb 22 2019 00:00:00 GMT+0800 (中国标准时间) -> '2019-02-22 00:00:00'

将Date对象转换为需要的字符串格式。

代码语言:javascript
复制
this.starttime = this.timevalue[0].getFullYear() + '-' + (this.timevalue[0].getMonth() + 1) + '-' + this.timevalue[0].getDate() + ' ' + this.timevalue[0].getHours() + ':' +this.timevalue[0].getMinutes() + ':' + this.timevalue[0].getSeconds(),
this.endtime = this.timevalue[1].getFullYear() + '-' + (this.timevalue[1].getMonth() + 1) + '-' + this.timevalue[1].getDate() + ' ' + this.timevalue[1].getHours() + ':' +this.timevalue[1].getMinutes() + ':' + this.timevalue[1].getSeconds()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019/03/05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档