javascript convert standard time into "yyyy-MM-dd HH:mm:ss" format
The first to convert standard time to "yyyy-MM-dd" format
which is:year month day
The obtained time format is: Thu Nov 12 2020 17:27:02 GMT+0800 (China Standard Time);
var date =newDate();// 核心代码,可自行封装functionconverTimeOfYMD(date){
returnnewDate(date).toISOString().slice(0,10);}
console.log(converTimeOfYMD(date))
Conversion result: 2020-11-12
The second way to convert the standard time into "yyyy-MM-dd HH:mm:ss" format
which is:Year-month-day hour-minute-second
The obtained time format is: Thu Nov 12 2020 17:27:02 GMT+0800 (China Standard Time);
var date =newDate();// 核心代码,可自行封装functionconverTimeOfHMS(date){
var json_date =newDate(date).toJSON();returnnewDate(newDate(json_date)+8*3600*1000).toISOString().replace(/T/g," ").replace(/\.[\d]{3}Z/,"");}
console.log(converTimeOfHMS(date))