Time format conversion

how to convert the time format of 2018-08-06T10:00:00.000Z to local time is similar to 2018-08-06 18:00:00

Mar.23,2022

first convert new Date ("2018-08-06T10:00:00.000Z") to get Mon Aug 06 2018 18:00:00 GMT+0800 (China Standard time) . Later, you can use moment or encapsulate a time conversion


directly use third-party libraries, such as moment (heavier) or date-fns (slightly lighter)


.

use it first:

var date = new Date('2018-08-06T10:00:00.000Z')
function formatDate(date) {
  var year = date.getFullYear()
  var month = format(date.getMonth() + 1)
  var da = format(date.getDate())
  var h = format(date.getHours())
  var m = format(date.getMinutes())
  var s = format(date.getSeconds())
  return year + '-' + month + '-' + da + ' ' + h + ':' + m + ':' + s
}
function format(val) {
  return Number(val) < 10 ? '0' + val : '' + val
}
console.log(formatDate(date))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be8ef1-3191f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be8ef1-3191f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?