Advertisement
killerbng

Custom Clocks - Console App

Mar 5th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import requests
  2. import json
  3. from datetime import datetime
  4. from pytz import timezone
  5. import pytz
  6.  
  7. def get_time(tz):
  8.     now = datetime.now()
  9.     fmt = '%Y-%m-%d %H:%M:%S'
  10.     eastern = timezone('US/Eastern')
  11.     new_tz = timezone(tz)
  12.     loc_dt = eastern.localize(datetime(now.year, now.month, now.day, now.hour, now.minute, now.second))
  13.     new_dt = loc_dt.astimezone(new_tz)
  14.     new_dt.strftime(fmt)
  15.     new_dt = str(new_dt)
  16.     new_dt = new_dt.replace("None", "")
  17.     return new_dt
  18.  
  19.  
  20. print("East Coast US: " + str(get_time('US/Eastern'))+"\n")
  21. print("Moscow, Russia: " + str(get_time('Europe/Moscow'))+"\n")
  22. print("Melbourne, Australia: " + str(get_time('Australia/Melbourne'))+"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement