Created
November 16, 2015 16:30
-
-
Save quest4i/63b9b68aed3191564a9f to your computer and use it in GitHub Desktop.
This file contains 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
import time | |
from datetime import datetime | |
import pytz # $ pip install pytz | |
from tzlocal import get_localzone # $ pip install tzlocal | |
# get local timezone | |
local_tz = get_localzone() | |
# test it | |
# utc_now, now = datetime.utcnow(), datetime.now() | |
ts = time.time() | |
utc_now, now = datetime.utcfromtimestamp(ts), datetime.fromtimestamp(ts) | |
local_now = utc_now.replace(tzinfo=pytz.utc).astimezone(local_tz) # utc -> local | |
assert local_now.replace(tzinfo=None) == now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment