Last active
May 5, 2019 02:56
-
-
Save CrashLaker/2f1bc49f22ab6237643c5aed987e9dd3 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 datetime | |
import pytz | |
timestamp = 1556668800.0 | |
date = datetime.datetime.utcfromtimestamp(timestamp) | |
print(date) # 2019-05-01 00:00:00 | |
# Applying timezone without converting it | |
date_sp = pytz.timezone("America/Sao_Paulo").localize(date) | |
print(date_sp.strftime(fmt)) # 2019-05-01 00:00:00 -03-0300 | |
# Then converting it to UTC | |
date_utc = date_sp.astimezone(tz=pytz.utc) | |
print(date_utc.strftime(fmt)) # 2019-05-01 03:00:00 UTC+0000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment