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?
Asked
Active
Viewed 4,965 times
2

SrinivasDJ
- 319
- 1
- 5
- 10
-
I am using java, I tried with examples but I have to convert to long type first and then pass that string to format method like SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd"); String date = sdf.format(created_time); but throwing an exception – SrinivasDJ Feb 11 '16 at 03:50
2 Answers
2
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.

sideroxylon
- 4,338
- 1
- 22
- 40
-
Yes, it's javascript (sorry - I missed your tag). Maybe [this](http://stackoverflow.com/questions/11839246/how-to-convert-timestamp-to-date-in-java) helps with java. – sideroxylon Feb 11 '16 at 05:29
-
Thanks for the update I have got the answer from [link](http://stackoverflow.com/questions/35330889/convert-date-string-to-readable-date-format) – SrinivasDJ Feb 11 '16 at 05:39
0
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

Garret Khougaz
- 11
- 2