js 时间格式转化 UTC yyyy-MM-dd'T'HH:mm:ss.SSS'Z' 转 new Date


(new Date).toISOString() 

// 获取这种格式 yyyy-MM-dd'T'HH:mm:ss.SSS'Z'

//  2021-08-04T02:09:37.959Z"

 

var a = (new Date).toISOString()

var date =  new Date(a)

// 在解决时间格式

//  Wed Aug 04 2021 10:11:33 GMT+0800 (中国标准时间)

getCurrentDate(date ,2)

 

// 转化方法

function getCurrentDate( date,format) {
//  var now = new Date()
  var now  =  date
  var year = now.getFullYear() // 得到年份
  var month = now.getMonth()// 得到月份
  var date = now.getDate()// 得到日期
  var hour = now.getHours()// 得到小时
  var minu = now.getMinutes()// 得到分钟
  var sec = now.getSeconds()// 得到秒
  month = month + 1
  if (month < 10) month = '0' + month
  if (date < 10) date = '0' + date
  if (hour < 10) hour = '0' + hour
  if (minu < 10) minu = '0' + minu
  if (sec < 10) sec = '0' + sec
  var time = ''
  // 精确到天
  if (format === 1) {
    time = year + '-' + month + '-' + date
  } else if (format === 2) { // 精确到分
    time = year + '-' + month + '-' + date + ' ' + hour + ':' + minu + ':' + sec
  }
  return time
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM