4

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?

Community
  • 1
  • 1
devs
  • 541
  • 2
  • 13
  • 27

1 Answers1

10

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;
adeneo
  • 312,895
  • 29
  • 395
  • 388