If you print the result for the following -
print(cet.localize(datetime.datetime(2000, 6, 1)).utcoffset())
You will notice that it gives a datetime.timedelta()
object which has both days as well as second.
So for timezones that are UTC - <something>
, this actually gives days as -1
and then the remaining in seconds. Example -
In [84]: cet = pytz.timezone("America/Los_Angeles")
In [87]: cet.localize(datetime.datetime(2000, 6, 1)).utcoffset()
Out[87]: datetime.timedelta(-1, 61200)
To get the info about the actual offset , you need to use both days
as well as seconds
, using a code like (For the above timezone - America/Los_Angeles
) -
In [88]: int((cet.localize(datetime.datetime(2000, 6, 1)).utcoffset().days*60*60*24 + cet.localize(datetime.datetime(2000, 6, 1)).utcoffset().seconds)/60)
Out[88]: -420
Also, I believe when you are doing - new Date(2000, 5, 1).getTimezoneOffset();
in javascript, I think it is giving you the timezone offset from UTC for today's date, rather than the date 2000/05/01
(Because for the date - 2000/05/01
the correct offset is what you are getting from python - 240
) . You may checkout TimezoneJS
for getting the timezone specific as well as date specific offsets, etc.