Source From Here
Install pytz
I am using pytz, which is a time zone definitions package. You can install it using Easy Install. On Ubuntu, do this:
Add time zone information to a naive datetime object
Add non-UTC time zone information to a naive datetime object
datetime.replace() does not handle daylight savings time correctly. The correct way is to use timezone.localize() instead. Using datetime.replace() is OK when working with UTC as shown above because it does not have daylight savings time transitions to deal with. See the pytz documentation.
Convert time zones
List time zones
There are 559 time zones included in pytz. Here's how to print the Asia time zones:
Execution output:
Install pytz
I am using pytz, which is a time zone definitions package. You can install it using Easy Install. On Ubuntu, do this:
Add time zone information to a naive datetime object
Add non-UTC time zone information to a naive datetime object
datetime.replace() does not handle daylight savings time correctly. The correct way is to use timezone.localize() instead. Using datetime.replace() is OK when working with UTC as shown above because it does not have daylight savings time transitions to deal with. See the pytz documentation.
Convert time zones
List time zones
There are 559 time zones included in pytz. Here's how to print the Asia time zones:
- from pytz import all_timezones
- print len(all_timezones)
- for zone in all_timezones:
- if 'Asia' in zone:
- print zone
沒有留言:
張貼留言