Created
May 5, 2019 02:59
-
-
Save CrashLaker/3d2c5734e788fd552d31068c60459867 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_utc = pytz.utc.localize(date) | |
print(date_utc.strftime(fmt)) # 2019-05-01 00:00:00 UTC+0000 | |
# Then converting it to UTC | |
date_sp = date_utc.astimezone(tz=pytz.timezone("America/Sao_Paulo")) | |
print(date_sp.strftime(fmt)) # 2019-04-30 21:00:00 -03-0300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment