zoukankan      html  css  js  c++  java
  • JS 20200101T00:00:00.000000Z 日期格式转换、Sun Jul 04 2021 00:00:00 GMT+0800 (中国标准时间)转20210704 00:00

    日期转换格式

    2020-06-27T14:20:27.000000Z 时间格式转换成 2020-06-27 14:20:27

    1 function rTime(date) {
    2     var json_date = new Date(date).toJSON();
    3     return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
    4 }
    5 let date = rTime('2020-06-27T14:20:27.000000Z');
    6 console.log(date) // 2020-06-27 14:20:27

    toJSON() 方法可以将 Date 对象转换为字符串,并格式化为 JSON 数据格式。

    自己项目中的
     1 // 时间过滤
     2                     this.List[i].date = this.List[i].requestUserTime;
     3 
     4                     function rTime(date) {
     5                         var json_date = new Date(date).toJSON();
     6                         return new Date(+new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/,
     7                             '')
     8 
     9                     }
    10 
    11                     this.List[i].date1 = rTime(this.List[i].date);

     Sun Jul 04 2021 00:00:00 GMT+0800 (中国标准时间)转2021-07-04 00:00

    
    
    timeFormat(time) {
          // 时间格式化 2019-09-08
          let year = time.getFullYear();
          let month = time.getMonth() + 1 > 10 ? time.getMonth()+1 : '0'+(time.getMonth()+1);
          let day = time.getDate() >= 10 ? time.getDate() : "0" + time.getDate();
          let h = time.getHours()>= 10 ? time.getHours() : "0" + time.getHours();              //获取当前小时数(0-23)
          let m = time.getMinutes()>= 10 ? time.getMinutes() : "0" + time.getMinutes();         //获取当前分钟数(0-59)
          console.log(year + "-" + month + "-" + day+ " " + h+ ":" + m)
          return year + "-" + month + "-" + day+ " " + h+ ":" + m;
          
        },
    
    
    
     
  • 相关阅读:
    vs2013 调用只有dll文件的动态库(一)
    剑指offer 34.二叉树中和为某一值的路径
    JQuery中bind和unbind函数与onclick绑定事件区分
    实现 select中指定option选中触发事件
    页面中的checkbox多选值获取
    页面中href链接的碰撞
    页面中onclick事件引号问题
    页面间传输参数(两种传参方法)
    js的非空校验
    时间控件,选择日期
  • 原文地址:https://www.cnblogs.com/liazhimao/p/13826697.html
Copyright © 2011-2022 走看看