Skip to content

Instantly share code, notes, and snippets.

@jcinis
Created November 3, 2016 09:44
Show Gist options
  • Save jcinis/97492c8c506dc23b22e94380d00053f5 to your computer and use it in GitHub Desktop.
Save jcinis/97492c8c506dc23b22e94380d00053f5 to your computer and use it in GitHub Desktop.
Shibuya, Tokyo to Williamsburg, New York door to door
from datetime import datetime
from pytz import timezone
start = '2016-11-02 13:00:00'
start_timezone = 'Asia/Tokyo'
end = '2016-11-02 18:18:00'
end_timezone = 'US/Eastern'
start_native_dt = datetime.strptime(start, "%Y-%m-%d %H:%M:%S")
end_native_dt = datetime.strptime(end, "%Y-%m-%d %H:%M:%S")
start_localized_dt = timezone(start_timezone).localize(start_native_dt)
end_localized_dt = timezone(end_timezone).localize(end_native_dt)
delta = end_localized_dt - start_localized_dt
s = delta.total_seconds()
hours = s // 3600
s = s - (hours * 3600)
minutes = s // 60
seconds = s - (minutes * 60)
print '%s:%s:%s' % (hours, minutes, seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment