
Untitled
By: a guest on
Aug 9th, 2012 | syntax:
None | size: 0.58 KB | hits: 6 | expires: Never
Python: Weird behavior with pytz timezones
from pytz import timezone
bsas = timezone('America/Argentina/Buenos_Aires')
gmt_plus_3 = timezone('Etc/GMT+3')
gmt_min_3 = timezone('Etc/GMT-3')
# Date and time at this momement: 2012-07-26 10:23:01
fmt = '%Y-%m-%dT%H:%M:%S'
datetime.now(bs).strftime(fmt) #'2012-07-26T10:23:01' <-- GOOD!
datetime.now(gmt_min_3).strftime(fmt) #'2012-07-26T16:25:21' <-- WRONG!
datetime.now(gmt_plus_3).strftime(fmt) #'2012-07-26T10:23:01' <-- GOOD! WTF!
GMT-3 should be 10:23:01 and gives me 16:23:01
GMT+3 should be 16:23:01 and gives me 10:23:01