Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between pytz.UTC and pytz.timezone('GMT')

Tags:

pytz

pytz's documentation says:

Note that this instance [pytz.timezone('UTC')] is not the same instance (or implementation) as other timezones with the same meaning (GMT, Greenwich, Universal, etc.).

and indeed:

>>> pytz.timezone('UTC') is pytz.timezone('GMT')
False

So... what's the difference?
When should I use pytz.timezone('UTC') and when should I use pytz.timezone('GMT')?

like image 496
Jonathan Livni Avatar asked Apr 07 '13 13:04

Jonathan Livni


1 Answers

The UTC implementation is a tzinfo implementation that will at all times return 0 minutes offset.

The timezone you get when you do pytz.timezone('GMT') is the GMT timezone defined in the Olson database. It also will return 0 at all times, but in a more complicated manner.

Use UTC.

like image 157
Lennart Regebro Avatar answered Sep 25 '22 15:09

Lennart Regebro