How do I convert the “time” from the Meetup API to a recognizable format?

假装没事ソ 提交于 2019-12-24 00:55:06

问题


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

Here's the Meetup API's definition of time:

Event start time in milliseconds since the epoch, or relative to the current time in the d/w/m format.

Here's the type of value I see returned in the JSON:

"time": 1382742000000,

Any advice about how to convert it into something recognizable?


回答1:


You can construct a date object like this

var date = new Date(milliseconds);

And then you could apply any format you want using Date properties




回答2:


Try this

// 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;



回答3:


moment.js library can help very well

moment(1382742000000) will give you object and inside of it you can see:

Fri Oct 25 2013 19:00:00



来源:https://stackoverflow.com/questions/19596875/how-do-i-convert-the-time-from-the-meetup-api-to-a-recognizable-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!