• JavaScript 将 yyyyMMddTHH:mm:ssZ 与 yyyyMMdd HH:mm:ss 格式的日期转换成 dd/MM/yyyy HH:mm:ss 格式


    // 将 yyyy-MM-ddTHH:mm:ssZ 与 yyyy-MM-dd HH:mm:ss 格式的日期转换成 dd/MM/yyyy HH:mm:ss 格式
    function formatDateTime(arg) {
      console.log('原数据:' + arg)
      if (arg) {
        // IE上的处理
        if ((!!window.ActiveXObject || 'ActiveXObject' in window) && arg.indexOf('T') === -1) {
          arg = arg.replace(/-/g, '/').replace(/\./g, '/')
        }
        let date = new Date(arg)
        let Y = date.getFullYear()
        let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
        let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
        let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
        let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
        let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : gate.getSeconds()
    
        let dateTimeStr = D + '/' + M + '/' + Y + ' ' + h + ':' + m + ':' + s
        console.log('转换后的数据:' + dateTimeStr)
        if (dateTimeStr === 'NaN/NaN/NaN NaN:NaN:NaN') {
          return arg
        }
        return dateTimeStr
      }
      return arg
    }
    
    let str = '2021-12-31T08:00:00Z'
    let str2 = '2021-12-31 08:00:00'
    console.log(formatDateTime(str), formatDateTime(str2))
    

      

  • 相关阅读:
    mysql实战45讲
    goland破解
    主从复制系列C
    主从复制系列B
    主从复制系列A
    sshd配置文件详解
    MySQL源码 数据结构array
    MySQL源码 information_schema新增表
    MySQL5.6 基于db的并行复制
    mysql 限制并发select patch
  • 原文地址:https://www.cnblogs.com/QingXiaxu/p/15612569.html
Copyright © 2020-2023  润新知