问题
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