标准时间转换

不拼接方式转换

Posted by callrenjie on January 7, 2021

不用拼接转换标准时间格式

如何将new Date()转换为标准的时间格式(YYYY-MM-DD HH:mm:ss),直接在js里面,不使用moment,也不使用getFullYear(),getMonth()这样拼接的方法。

1

执行结果:

toISOString 2019-05-30T02:31:44.618Z
toUTCString Thu, 30 May 2019 02:31:44 GMT
toString() Thu May 30 2019 10:31:44 GMT+0800 (中国标准时间)
toDateString() Thu May 30 2019
toTimeString() 10:31:44 GMT+0800 (中国标准时间)
toLocaleString() 2019-5-30 10:31:44
toLocaleTimeString() 10:31:44
toLocaleDateString() 2019-5-30
format() 2019-05-30 10:31:44