Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Python return a negative timezone value?

For time.timezone, the Python documentation says:

The offset of the local (non-DST) timezone, in seconds west of UTC (negative in most of Western Europe, positive in the US, zero in the UK).

Does anybody know why it returns a negative value for most of Western Europe? These countries are in a positive offset, and not in a negative one.

Example: Brussels is in UTC+1 timezone...

like image 629
gecco Avatar asked Aug 16 '12 09:08

gecco


People also ask

Can timezone be negative?

A negative offset indicates that the time is west of UTC and a positive offset indicates that the time is east of UTC. Year offset. Year offset indicates the difference in years between the current Gregorian year and the current year in the calendar used with the time zone for your system.

What is timezone in Python?

The timezone, in general, is used to display the conversion of date and time between timezones, which means it is used to display the timezone it is using to print the time and date. In Python, the timezone is related to time concepts where two modules display timezones are time module and datetime module.

Which Python library is used for time zone?

It basically refers to the local time of a region or country. Most of the time zones are offset from Coordinated Universal Time (UTC), the world's standard for time zone. In order to get the current time of different time zones, we will be using the pytz python library.


1 Answers

This is a Unix artefact. Although the standard numeric description for timezones is in hours and minutes east from UTC (UTC+1 for Brussels, UTC-5 for New York, etc.) the Unix timezone is measured in seconds west from UTC.

From http://pubs.opengroup.org/onlinepubs/7908799/xsh/tzset.html:

The external variable timezone is set to the difference, in seconds, between Coordinated Universal Time (UTC) and local standard time, for example:

TZ  timezone
EST 5*60*60
GMT 0*60*60
JST -9*60*60
MET -1*60*60
MST 7*60*60
PST 8*60*60

As to why Unix has it backwards, I'd guess it's a historical accident, probably because Unix was originally developed in the USA.

like image 172
ecatmur Avatar answered Sep 28 '22 08:09

ecatmur