Skip to content

Instantly share code, notes, and snippets.

@CrashLaker
Last active May 5, 2019 02:56
Show Gist options
  • Save CrashLaker/2f1bc49f22ab6237643c5aed987e9dd3 to your computer and use it in GitHub Desktop.
Save CrashLaker/2f1bc49f22ab6237643c5aed987e9dd3 to your computer and use it in GitHub Desktop.
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