Advertisement
khangnguyen

datetime-conversion

Sep 26th, 2012
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import pytz, dateutil.parser
  2. # Z is for timezone
  3. gmtTime = dateutil.parser.parse("2011-07-14T6:00:00.000Z")
  4.  
  5. # To convert naive time to tz-aware time
  6. now-aware = pytz.UTC.localize(naive-time)
  7.  
  8. # To convert UTC time to localtime
  9. # weird huh? shouldnt it be Asia/Hanoi
  10. localtime = utcTime.astimezone(pytz.timezone("Asia/Ho_Chi_Minh"))
  11.  
  12.  
  13. # Create a datetime variable with timezone
  14. start = datetime(1970, 1, 1, tzinfo=pytz.UTC)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement