这是什么样的日期时间格式?即:“1551927028”[复制]

问题描述 投票:2回答:3

这个问题在这里已有答案:

我正在使用CryptoCompare的api,here is the link

响应包含一个字段名称published_on,我试图使用moment转换为适当的日期时间格式,但它不起作用。

有人知道格式或如何将其转换为正常的日期时间格式。我正在使用javascript

enter image description here

javascript api datetime momentjs
3个回答
1
投票

这个日期是Unix时间戳。由于您正在使用时刻,请执行以下操作将其转换为日期格式

moment.unix(1551929623).format('DD/MM/YYYY')

请更改适合您的格式。

片刻文档链接https://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/


2
投票

这叫做Unix time stamp

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感谢您的信息

© www.soinside.com 2019 - 2024. All rights reserved.