Skip to content

Instantly share code, notes, and snippets.

@ytjohn
Created November 1, 2014 20:01
Show Gist options
  • Save ytjohn/c0fa4cea572eaf2b0ba4 to your computer and use it in GitHub Desktop.
Save ytjohn/c0fa4cea572eaf2b0ba4 to your computer and use it in GitHub Desktop.
show multiple timezone
#!/usr/bin/env python
from datetime import datetime
from dateutil import tz
import collections
import time
utczone = tz.gettz('UTC')
utc = datetime.utcnow()
utc = utc.replace(tzinfo=utczone)
zones = ['America/New_York',
'Europe/Stockholm',
'Europe/Moscow',
'America/Los_Angeles',
'Europe/London',
'America/Tijuana',
'Asia/Tokyo'
]
# print "{0}, {1}".format(utc, 'UTC')
utcs = "{0}U".format(str(utc))
list = {utcs: '** UTC **'}
for zone in zones:
ts = utc.astimezone(tz.gettz(zone))
# print str(ts)
list[str(ts)] = zone
# print "{0}, {1}".format(ts, zone)
od = collections.OrderedDict(sorted(list.items()))
for k, v in od.iteritems():
print "{0}, {1}".format(k,v)
@ytjohn
Copy link
Author

ytjohn commented Nov 1, 2014

2014-11-01 13:01:32.325095-07:00, America/Tijuana
2014-11-01 16:01:32.325095-04:00, America/New_York
2014-11-01 20:01:32.325095+00:00, Europe/London
2014-11-01 20:01:32.325095+00:00U, ** UTC **
2014-11-01 21:01:32.325095+01:00, Europe/Stockholm
2014-11-01 23:01:32.325095+03:00, Europe/Moscow
2014-11-02 05:01:32.325095+09:00, Asia/Tokyo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment