Javascript 如何将“转换为”;时间“;从Meetup API到可识别的格式?

Javascript 如何将“转换为”;时间“;从Meetup API到可识别的格式?,javascript,jquery,json,meetup,Javascript,Jquery,Json,Meetup,以下是Meetup API对时间的定义: 事件开始时间(以毫秒为单位,从历元开始),或相对于当前时间(d/w/m格式) 以下是我在JSON中看到的返回值类型: "time": 1382742000000, 关于如何将其转换为可识别的内容,有什么建议吗?试试这个 // Convert milliseconds since since 00:00:00 UTC, Thursday, 1 January 1970 (the epoch in Unix speak) var date = new Da

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

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

以下是我在JSON中看到的返回值类型:

"time": 1382742000000,
关于如何将其转换为可识别的内容,有什么建议吗?

试试这个

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

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

var date = new Date(milliseconds);

然后,您可以使用properties应用您想要的任何格式。js库可以很好地提供帮助

力矩(1382742000000) 我会给你一个目标 在里面你可以看到:


2013年10月25日星期五19:00:00

var dt=new Date(1382742000000)的可能重复项这将为您提供Date对象&要显示它,请使用此dt.toString()这将为您提供一个输出“Sat Oct 26 2013 04:30:00 GMT+0530(印度标准时间)”,如果您使用python,则datetime.datetime.fromtimestamp(ms/1000.0)有效。我知道这个问题是针对javascript的,但这是google上出现的第一个帖子。以防任何使用不同语言的人需要知道:这里的“纪元”与Unix纪元相同,命名为“1970年1月1日00:00:00 UTC”,您不需要
*1000
。JavaScript使用毫秒,这是我们已经拥有的。