内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
使用Node.js,我想格式化一个Date
转换为以下字符串格式:
var ts_hms = new Date(UTC); ts_hms.format("%Y-%m-%d %H:%M:%S");
我该怎么做?
Date有一个toISOString
方法
new Date().toISOString()
> '2012-11-04T14:51:06.157Z'
然后设置:
new Date().toISOString().
replace(/T/, ' '). // replace T with a space
replace(/\..+/, '') // delete the dot and everything after
> '2012-11-04 14:55:45'