Created
April 27, 2017 15:47
-
-
Save philipbl/dcd4b93f80fbc8f6f8e0dce25b3e49c4 to your computer and use it in GitHub Desktop.
Experimenting with time zones with Python datetime module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from datetime import datetime | |
import pytz | |
epoch_time = 1493307387 | |
dt1 = datetime.fromtimestamp(epoch_time) | |
print("Local time:", dt1) | |
print("Not tz aware:", dt1.tzinfo) | |
print() | |
dt2 = datetime.utcfromtimestamp(epoch_time) | |
print("UTC time:", dt2) | |
print("Not tz aware:", dt2.tzinfo) | |
print() | |
dt3 = dt2.replace(tzinfo=pytz.utc) | |
print("UTC time:", dt3) | |
print("tz aware:", dt3.tzinfo) | |
print() | |
dt4 = datetime.fromtimestamp(epoch_time, tz=pytz.utc) | |
print("UTC time:", dt4) | |
print("tz aware:", dt4.tzinfo) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment