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 a timestamp is used, for example the fromdate parameter in /questions, what timezone are dates in? Is the number supposed to be in milliseconds or in seconds?

To get the current time to pass as a parameter in JavaScript should I use:

new Date().getTime();

or:

Math.round(((new Date()).getTime()-Date.UTC(1970,0,1))/1000);
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

The date is Unix Epoch time, which is the number of seconds since 1/1/1970. The "time zone" is UTC, which is nearly equivalent to GMT. You can convert from UTC to local time in javascript using the method outlined here.

Here are the functions I use to convert back and forth (code is C#):

public static DateTime ConvertFromUnixTimestamp(double timestamp)
{
    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    return origin.AddSeconds(timestamp);
}

public static double ConvertToUnixTimestamp(DateTime date)
{
    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    TimeSpan diff = date.ToUniversalTime() - origin;
    return Math.Floor(diff.TotalSeconds);
}
share|improve this answer
1  
+1 although UTC is not a Time Zone but a time standard and Time Zones are expressed as negative or positive offsets from UTC. –  systempuntoout Aug 9 '10 at 18:44
    
@system: true dat. Updated. –  Dave Swersky Aug 9 '10 at 19:13
add comment

You must log in to answer this question.

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