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;
          
        },
    
    
    
     
  • 相关阅读:
    树形目录生成器.bat
    Google 搜索截图
    Expo 2010 Japan Pavilion
    WinCE应用程序开发创建文件或文件夹
    Oracle 获取每月最后一天的函数
    Oracle的外连接符号(+)
    关于项目中找不到某个配置xml文件的问题
    通過反編譯跟蹤JSP頁面
    JSP 一些基本语法
    page request session application 范围
  • 原文地址:https://www.cnblogs.com/liazhimao/p/13826697.html
Copyright © 2011-2022 走看看