中国标准时间、2021

1.将中国标准时间转换成yyyy-xx-nn aa-bb-cc

中国标准时间:
Thu May 12 2019 08:00:00 GMT+0800 (中国标准时间)

var d = new Date('Thu May 12 2019 08:00:00 GMT+0800 (中国标准时间)'); 
d=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
2.将yyyy-xx-nn aa-bb-cc转换成中国标准时间
 var s=new Date(stime).getTime();
          var d=new Date(etime).getTime();
3.如果遇到解析毫秒时间的时候,出现2020-7-8 11-7 可以使用分开解析
 let d = new Date(item[0].create_time);//这个是你需要解析的时间
let year = d.getFullYear().toString();
 let month = (d.getMonth()+1).toString();
 let day = (d.getDate()).toString();
 let hour = (d.getHours()).toString();
 let min = (d.getMinutes()).toString();
 let second = (d.getSeconds()).toString();
 if (year.len >h=1){
     year='0'+year;
 }
 if (month.len >h=1){
     month='0'+month;
 }
 if (day.len >h=1){
     day='0'+day;
 }
 if (hour.len >h=1){
     hour='0'+hour;
 }
 if (min.len >h=1){
     min='0'+min;
 }
 if (second.len >h=1){
     second='0'+second;
 }
 d = year+'-'+month+'-'+day+' '+hour+':'+min+':'+second;

4.标准时间转换成毫秒数
demo:
将Sat Nov 07 2020 16:52:13 GMT+0800 (中国标准时间)转成1604739133000
1.将转换的方法封装出来

 dateToMs (date) {
                let resu<  = new Date(date).getTime();
                return resu< ;
            },

2.调用该方法

console.log(this.dateToMs(demoTime))
5.将毫秒数转换成yyyy-xx-mm

1.关于时间转换的两个方法

 getMyDate(str) {
                let oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + this.addZero(oMonth) + '-' + this.addZero(oDay) + ' ' + this.addZero(oHour) + ':' +
                        this.addZero(oMin) + ':' + this.addZero(oSen);
                return oTime;
            },
   addZero(num) {
       if (parseInt(num)  10) {
           num = '0' + num;
       }
       return num;
   },

2.调用该方法就可以转换成 2020-11-07 18:55:13

6、2021-01-11T09:49:43.000+0000转yyyy-mm-mm aa-bb-cc
  renderTime(date) {
    var dateee = new Date(date).toJSON();
    return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
  },
最新回复(0)
/jishu5HWq_2FVyL8AFB4Ry3oiu42iyki_2FDgSzV6g9LDODe0_2FPU_3D4858462
8 简首页