Advertisement
J2897

World Times

Jan 17th, 2022 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from datetime import datetime as dt
  2. from pytz import timezone as tz # pip install pytz
  3.  
  4. britian = ['GB']
  5.  
  6. american = [
  7.     'America/Vancouver',
  8.     'America/Toronto',
  9.     'America/Los_Angeles',
  10.     'America/New_York'
  11. ]
  12.  
  13. states = [
  14.     'US/Pacific',
  15.     'US/Mountain',
  16.     'US/Central',
  17.     'US/Eastern',
  18. ]
  19.  
  20. world = [
  21.     'Asia/Seoul',
  22.     'Hongkong',
  23.     'Asia/Singapore'
  24. ]
  25.  
  26. def get_times(zones):
  27.     time_list = list()
  28.     time_tuple = tuple()
  29.     for zn in zones:
  30.         time_now = dt.now(tz=tz(zn)).replace(tzinfo=None)
  31.         time_string = time_now.isoformat(sep=' ', timespec='minutes')
  32.         zone = zn.rsplit('/', 1)
  33.         time_tuple = time_string, zone[-1:][0]
  34.         time_list.append(time_tuple)
  35.     return time_list
  36.  
  37. print('Britain:')
  38. for x in get_times(britian):
  39.     print(x[0], ' - ', x[1])
  40. print()
  41.  
  42. print('America:')
  43. for x in get_times(american):
  44.     print(x[0], ' - ', x[1])
  45. print()
  46.  
  47. print('Major USA Time Zones:')
  48. for x in get_times(states):
  49.     print(x[0], ' - ', x[1])
  50. print()
  51.  
  52. print('Global:')
  53. for x in get_times(world):
  54.     print(x[0], ' - ', x[1])
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement