Skip to content

Instantly share code, notes, and snippets.

@ccwang002
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccwang002/2287da0da0bc970fe7df to your computer and use it in GitHub Desktop.
Save ccwang002/2287da0da0bc970fe7df to your computer and use it in GitHub Desktop.
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