Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Python: Weird behavior with pytz timezones
  2. from pytz import timezone
  3. bsas = timezone('America/Argentina/Buenos_Aires')
  4.  
  5. gmt_plus_3 = timezone('Etc/GMT+3')
  6. gmt_min_3 = timezone('Etc/GMT-3')
  7.  
  8. # Date and time at this momement: 2012-07-26 10:23:01
  9.  
  10. fmt = '%Y-%m-%dT%H:%M:%S'
  11. datetime.now(bs).strftime(fmt)  #'2012-07-26T10:23:01' <-- GOOD!
  12.  
  13. datetime.now(gmt_min_3).strftime(fmt)  #'2012-07-26T16:25:21' <-- WRONG!
  14.  
  15. datetime.now(gmt_plus_3).strftime(fmt)  #'2012-07-26T10:23:01' <-- GOOD! WTF!
  16.        
  17. GMT-3 should be 10:23:01 and gives me 16:23:01
  18. GMT+3 should be 16:23:01 and gives me 10:23:01