When I am using this page for the Stack Exchange API /search path, I can see that it is generating time-stamps in this format:


What is this date format? How do I convert, to this time stamp, from

var date = new Date().getTime();


I got the specification from this doc , but I didn't get any method to convert, it is not just eliminating the millisecond values by dividing by 1000.

1 Answer 1


Since the .getTime() value is already in UTC, you can just divide by 1000, and round.

That is:

var apiDate = Math.round (new Date().getTime() / 1000);

works just fine.

apiDate is in "unix epoch time" and the API takes these values even if the API parameter is called a "Date".

But, if you want to truncate to the date only, just use:

var dateTime = new Date ();
dateTime.setUTCHours   (0);
dateTime.setUTCMinutes (0);
dateTime.setUTCSeconds (0);

var apiDate = Math.round (dateTime.getTime() / 1000);

See, also "How do I parse the dates from the API?".

  • 1
    I cant double like :) Commented Sep 29, 2013 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .