Skip to content

Instantly share code, notes, and snippets.

@CrashLaker
Created May 5, 2019 02:59
Show Gist options
  • Save CrashLaker/3d2c5734e788fd552d31068c60459867 to your computer and use it in GitHub Desktop.
Save CrashLaker/3d2c5734e788fd552d31068c60459867 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_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