Node.js 展开压缩的 ISO 日期时间
Node.js Expand compressed ISO Date Time
有没有 simple/native 方法可以将速记 ISO 格式转换为扩展标准格式?我相信这就是导致我的比较失败的原因(但很高兴被告知不是这样)。
我认为是简写的是这个
Short ISO Time: 20160524T054843Z
我拥有的普通 ISO 字符串是
Long ISO Time: 2016-05-18T11:46:21.982Z
然后当我尝试使用
进行比较时
${compareable.getHours()}:${compareable.getMinutes()}:${compareable.getSeconds()}:${compareable.getMilliseconds()}
我得到以下内容
Time difference: NaN:NaN:NaN:NaN
为什么你不试试 moment 包。 http://momentjs.com/
你可以试试这个:
var shortDate = '20160524T054843Z'
shortDate.replace(/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/, '--T::.000Z')
> "2016-05-24T05:48:43.000Z"
有没有 simple/native 方法可以将速记 ISO 格式转换为扩展标准格式?我相信这就是导致我的比较失败的原因(但很高兴被告知不是这样)。
我认为是简写的是这个
Short ISO Time: 20160524T054843Z
我拥有的普通 ISO 字符串是
Long ISO Time: 2016-05-18T11:46:21.982Z
然后当我尝试使用
进行比较时${compareable.getHours()}:${compareable.getMinutes()}:${compareable.getSeconds()}:${compareable.getMilliseconds()}
我得到以下内容
Time difference: NaN:NaN:NaN:NaN
为什么你不试试 moment 包。 http://momentjs.com/
你可以试试这个:
var shortDate = '20160524T054843Z'
shortDate.replace(/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/, '--T::.000Z')
> "2016-05-24T05:48:43.000Z"