【发布时间】:2019-07-28 21:09:31
【问题描述】:
我正在使用 CryptoCompare 的 api,here is the link
响应包含一个字段名 published_on,我尝试使用 moment 转换为适当的日期时间格式,但没有成功。
有人知道格式或如何将其转换为正常的日期时间格式。我正在使用 javascript
【问题讨论】:
标签: javascript api datetime momentjs
我正在使用 CryptoCompare 的 api,here is the link
响应包含一个字段名 published_on,我尝试使用 moment 转换为适当的日期时间格式,但没有成功。
有人知道格式或如何将其转换为正常的日期时间格式。我正在使用 javascript
【问题讨论】:
标签: javascript api datetime momentjs
console.log(+new Date()) // unix time stamp
console.log(new Date(1551929623 * 1000 )) //unix to normal date conversion
旁注: JS time stamp 以毫秒为单位,而UNIX time stamps 使用秒。 @JaromandaX 感谢您提供信息
【讨论】:
这个日期是 Unix 时间戳。由于您使用的是时刻,请执行以下操作将其转换为日期格式
moment.unix(1551929623).format('DD/MM/YYYY')
请更改适合您的格式。
Moment 文档链接https://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/
【讨论】:
new Date(1551929623 * 1000) - 不需要废话库
new Date(1551929623 * 1000) 没有任何问题。