如何将Meetup API中的“时间”转换为可识别的格式?

时间:2013-10-25 18:19:57

标签: javascript jquery json meetup

http://www.meetup.com/meetup_api/docs/2/event/

以下是Meetup API对时间的定义:

  

自纪元以来的事件开始时间(以毫秒为单位),或相对于d / w / m格式的当前时间。

这是我在JSON中看到的值的类型:

"time": 1382742000000,

有关如何将其转换为可识别的内容的任何建议吗?

3 个答案:

答案 0 :(得分:3)

您可以像这样构建一个日期对象

var date = new Date(milliseconds);

然后您可以使用Date属性

应用任何您想要的格式

答案 1 :(得分:2)

试试这个

// Convert milliseconds since since 00:00:00 UTC, Thursday, 1 January 1970 (the epoch in Unix speak)
var date = new Date(1382742000000);

// now get individual properties from the date object to construct a new format

// hours part from the timestamp
var hours = date.getHours();

// minutes part from the timestamp
var minutes = date.getMinutes();

// seconds part from the timestamp
var seconds = date.getSeconds();

// display time in our new format
var formattedTime = hours + ':' + minutes + ':' + seconds;

答案 2 :(得分:1)

moment.js库可以很好地帮助

矩(13827.42亿) 会给你一个对象 在里面你可以看到:

Fri Oct 25 2013 19:00:00