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?

1
  • 1
    This is not a JSON-specific date, but rather a UNIX timestamp. Commented Dec 7, 2012 at 0:16

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome, this date stuff can be really confusing sometimes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.