Last active
February 20, 2020 18:53
-
-
Save lossurdo/955768a74a8ae0a4fc1886486914c693 to your computer and use it in GitHub Desktop.
Convert UTC to your time zone
This file contains hidden or 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
#!/usr/bin/python3 | |
# coding: utf-8 | |
from datetime import datetime | |
# pip3 install pytz | |
import pytz | |
def convert(posix_timestamp, your_timezone='America/Sao_Paulo'): | |
utc_dt = datetime.utcfromtimestamp(posix_timestamp).replace(tzinfo=pytz.utc) | |
tz = pytz.timezone(your_timezone) | |
dt = utc_dt.astimezone(tz) | |
return dt.strftime('%Y-%m-%d %H:%M:%S') # Also print TZ: '%Y-%m-%d %H:%M:%S %Z%z' | |
if __name__=='__main__': | |
# confirmation on: https://www.epochconverter.com/ | |
# BR time zone: Sexta-feira, 18 de Janeiro de 2013 às 18:00:00 GMT-02:00 DST | |
print(convert(1358539200)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment