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;
          
        },
    
    
    
     
  • 相关阅读:
    WPF的布局--DockPanel
    WPF的布局--StackPanel
    C#中的不可空类型转为可空类型
    linux下安装nodejs及npm
    HTML DOM 事件对象 ondragend 事件
    pc端页面在移动端显示问题
    css设置文字上下居中,一行文字居中,两行或多行文字同样居中。
    超简单的gif图制作工具
    Git创建与合并分支
    props default 数组/对象的默认值应当由一个工厂函数返回
  • 原文地址:https://www.cnblogs.com/liazhimao/p/13826697.html
Copyright © 2011-2022 走看看