Javascript's Date does not work like you expect. But your python code is correct.
According to The epoch time listing, the epoch time for January 1, 2010 should be
1262304000
Python: (appears to be correct)
>>> (datetime(2010,1,1) - datetime(1970,1,1)).total_seconds()
1262304000.0
Javascript (appears to be wrong)
> new Date(2010,1,1).getTime()
1265011200000
or
> new Date(2010,1,1).getTime()/1000
1265011200
This is because Javascript date is not creating the date the way you expect. First, it creates the date in your current timezone, and not in UTC. So a "get current time" in javascript would be the clients time, whereas python would return the utc time. Also note that there is a bug in JS Date where the month is actually 0 based and not 1 based.
> new Date(2010,1,1,0,0,0,0)
Date 2010-02-01T08:00:00.000Z
> new Date(2010,0,1,0,0,0,0)
Date 2010-01-01T08:00:00.000Z
Javascript can create a date from an epoch time:
> new Date(1262304000000)
Date 2010-01-01T00:00:00.000Z
Which is correct.
Alternatively you could use the following JS function to get a more accurate time please note that the month still starts at 0 and not 1
> Date.UTC(2010,0,1)
1262304000000
time.time()
does the same thing. Also, if the total seconds is what you're after, why are you multiplying by 1000? I didn't thinktotal_seconds()
returned milliseconds. – Motorboattime.time()
does not do the same thing; this function returns the offset from the epoch for a givendatetime
object, whiletime.time()
only gives you the current timestamp. – Phocomelia