Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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:

fromdate=1380326400&todate=1380412800

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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?".

share|improve this answer
    
I cant double like :) –  Sarath Saleem Sep 29 '13 at 10:55
add comment

You must log in to answer this question.

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