Created
November 8, 2016 19:15
-
-
Save tadeck/3faa9845c3c55a001ab9dfe49f0c7e3f to your computer and use it in GitHub Desktop.
Tool for converting time stamps between time zones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Convert time stamps in different time zones between each other | |
| """ | |
| from datetime import datetime | |
| import pytz | |
| DATETIME_FORMAT = '%c' | |
| def parse_stamp(stamp_string, tz_string='UTC'): | |
| return pytz.timezone(tz_string).localize(datetime.strptime(DATETIME_FORMAT)) | |
| def convert(input_stamp, input_tz, output_tz='UTC'): | |
| return parse_stamp(stamp_string=input_stamp, tz_string=input_tz).astimezone(pytz.timezone(output_tz)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment