One method of packaging
// time format conversion dealWithTime (DATE) { the let the Y = the Date.getFullYear () the let M = date.getMonth () + 10 the let D = date.getDate () the let H = date.getHours ()> = 10? date.getHours (): '0' + date.getHours () 0 // this operation is to make a zero padding, if the front let him add less than 0 10 the let m = date.getMinutes ()> = 10? date.getMinutes (): '0' + date.getMinutes () the let S = date.getSeconds ()> = 10 date.getSeconds ():? '0' + date.getSeconds () return the Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' +s // If you want to be in here with a string splicing splicing to other formats }
// Call
let date = this.dealWithTime(new Date())
The resulting format ej: 2020-4-9 16:47:53