How to convert created_time filed value to date from Instagram media object

北城余情 提交于 2019-12-08 01:01:34

问题


I am wokring with instagram api. My requirement is how to convert or parse date from media object respose like "created_time": "1279340983"? any idea?


回答1:


Once you have the response from the Instagram API, do this:

var t = response.created_time;
var date = new Date(t);
console.log(date);

If the time stamp is 1279340983, then:

var date = new Date(1279340983);

will convert the stamp to a date/time in your computer's local time zone.




回答2:


The Instagram API responds with a "created_time" JSON object that is formatted as a Unix timestamp, AKA milliseconds since 00:00:00 1 Jan 1970.

Here is a great resource on how to convert Unix timestamps in various languages to human readable dates: https://www.epochconverter.com/programming/#javascript

Here is the Javascript:

 var myDate = new Date( response.created_time *1000);
 document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());

and this code creates:

Thu, 01 Jan 1970 00:00:01 GMT 12/31/1969, 4:00:01 PM



来源:https://stackoverflow.com/questions/35329944/how-to-convert-created-time-filed-value-to-date-from-instagram-media-object

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