Skip to content

Instantly share code, notes, and snippets.

@ccwang002 ccwang002/tz_convert.py
Last active Aug 29, 2015

Embed
What would you like to do?
Timezone Conversion
from datetime import datetime
from pytz import timezone # pip install pytz
# Setup remote time
remote_tz = timezone('US/Pacific') # PST for example
remote_dt = remote_tz.localize(datetime(2015, 5, 1, 14, 0)) # May 1, 2015 PM2:00 PST
# Setup Taipei local time
tpe = timezone('Asia/Taipei')
# Conversion
local_dt = remote_dt.astimezone(tpe)
print(local_dt) # May 2, 2015 AM5:00 CST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.