首页 > 解决方案 > Mailgun events API timestamp

问题描述

I'm making calls to the Mailgun events API but I'm confused by the timestamp format. Timestamps show as "timestamp": 1542251497.6072 or the longer format 1542358648.178141.

I can't find any reference to it in the documentation except their claim to follow "RFC822" specification.

How can I parse/convert these timestamps into JavaScript Date objects (GMT preferably)?

标签: javascriptdatemomentjsmailgun

解决方案


由于您已经在使用,moment只需使用以下unix方法:

moment.unix(1542251497.6072).format()    // "2018-11-14T19:11:37-08:00"
moment.unix(1542358648.178141).format()  // "2018-11-16T00:57:28-08:00"

哪个:

与 new Date(Number) 类似,您可以通过传递一个表示自 Unix 纪元(1970 年 1 月 1 日 12AM UTC)以来的毫秒数的整数值来创建时刻。


推荐阅读