200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 前端 年月日 时间戳 中国标准时间 国际标准时间 转换

前端 年月日 时间戳 中国标准时间 国际标准时间 转换

时间:2022-11-13 02:29:50

相关推荐

前端 年月日 时间戳 中国标准时间 国际标准时间 转换

嘀嘀嘀 ~ 前端日期相互转换来了

1. 国际标准时间转年月日

方法一:

-09-30T12:20:00.000Z 为国际标准时间 (国际标准时间和年月日时差为8个小时)

转换完成 结果为 .09.30 20:20:00

methods:{addZero(num) {return num < 10 ? '0' + num : num;},formatDateTime(date) {const time = new Date(Date.parse(date));time.setTime(time.setHours(time.getHours()));const Y = time.getFullYear() + '.';const M = this.addZero(time.getMonth() + 1) + '.';const D = this.addZero(time.getDate()) + ' ';const h = this.addZero(time.getHours()) + ':';const m = this.addZero(time.getMinutes()) + ':';const s = this.addZero(time.getSeconds());return Y + M + D + h + m + s;},}

方法二:

下面方法只是简单分割然后重组 格式化

-09-30T12:20:00.000Z 转换为年月日 就是-09-30 12:20:00

formateDate(date) {const arr = date.split('T');const d = arr[0];const darr = d.split('-');const t = arr[1];const tarr = t.split('.000');const marr = tarr[0].split(':');const dd =parseInt(darr[0]) +'-' +parseInt(darr[1]) +'-' +parseInt(darr[2]) +' ' +parseInt(marr[0]) +':' +parseInt(marr[1]) +':' +parseInt(marr[2]);return dd;}

转自:如何格式化和转换后台给的时间戳(-02-22T16:00:00.000Z)为标准的时间格式_const.的博客-CSDN博客

2. 中国标准时间转换年月日

function switchDate(standardTime) {if (standardTime != "") {let a = standardTime;var Month = a.getMonth() + 1;var MonthDate;var DayDate = a.getDate();var Day;if (Month < 10) {MonthDate = '0' + Month;} else {MonthDate = Month;}if (DayDate < 10) {Day = '0' + DayDate;} else {Day = DayDate;}var datetime = a.getFullYear() + "-" + MonthDate + "-" + Day;console.log(datetime)return datetime}}

中国标准时间standardTime =Sat Jan 01 1994 00:00:00 GMT+0800 (中国标准时间) 转之后是datetime= 1994-01-01

转自:中国标准时间转日期YYYY-MM-DD_M_SSY的博客-CSDN博客_中国标准时间怎么转成日期

3.时间戳转换年月日

转载:

时间戳转换、获取当前时间年月日 - vaelcy - 博客园

4.中国标准时间转换年月日

转载:

年月日转换为标准时间_imkaifan的博客-CSDN博客_年月日转标准时间

5.可以查看 安装 | Day.js中文网

下载js文件到项目 方便使用

欢迎大家前来探讨

如有侵权,请联系删除

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。