- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeDifference.py
More file actions
Latest commit
18 lines (11 loc) · 732 Bytes
/
Copy pathtimeDifference.py
File metadata and controls
18 lines (11 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fromdatetimeimportdatetime
CITIES= {'Los Angeles': '4:00', 'New York': '7:00', 'Caracas': '7:30', 'Buenos Aires': '9:00', 'London': '12:00',
'Rome': '13:00', 'Moscow': '15:00', 'Tehran': '15:30', 'New Delhi': '17:30', 'Beijing': '20:00', 'Canberra': '22:00'}
defcity_time_diff(city):
returndatetime.strptime(CITIES[city], '%H:%M')
deftime_difference(city_a, timestamp, city_b):
x=datetime.strptime(timestamp, '%B %d, %Y %H:%M')
diff=city_time_diff(city_b)-city_time_diff(city_a)
return'{d.year}-{d.month}-{d.day} {d.hour:02}:{d.minute:02}'.format(d=x+diff)
print(time_difference("New York", "December 31, 1970 13:40", "Beijing"))
# returns output like - 1971-1-1 02:40