Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting JSON string into date [duplicate]

Possible Duplicate:
Convert a Unix timestamp to time in Javascript

I'm trying to convert the string that this api returns for date. The format is 1351993013. I tried the following line of JS but the date is completely wrong.

var jsonDate = plugin.versions[0].date;
var pluginDate = new Date(jsonDate);

Which returns:

Fri Jan 16 1970

This is the first time I've tried to format a JSON date so it's a bit confusing. Can anyone help?

like image 856
devs Avatar asked Sep 11 '25 10:09

devs


1 Answers

That would be seconds, and javascript uses milliseconds which would be

1351993013​000

which would give you Sunday Nov 04 2012.

in other words:

var jsonDate = parseInt(plugin.versions[0].date, 10) * 1000;
like image 122
adeneo Avatar answered Sep 12 '25 23:09

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!