Reputation: 26642
The time is 15:0x in Stockholm (Europe). But I'm getting the localized time 1 hour wrong:
>>> datetime.datetime.now()
datetime.datetime(2015, 12, 17, 15, 2, 42, 633000)
>>> babel.dates.format_datetime(datetime.datetime.now(), 'full', tzinfo=pytz.timezone('Europe/Stockholm'),locale='en')
u'Thursday, December 17, 2015 at 4:02:49 PM Central European Standard Time'
>>>
What is the mistake?
Upvotes: 3
Views: 2804
Reputation: 85532
Explicit is better than implicit. Set the timezone for now
:
now = datetime.datetime.now(tz=pytz.timezone('Europe/Stockholm'))
Upvotes: 5
Reputation: 2495
The problem appears to have been the baked in local time of the datetime.datetime.now()
call. As mentioned in the comments, use datetime.datetime.utcnow()
for a timezone agnostic coordinated universal time
, or input the desired timezone info into the datetime call datetime.datetime.now(tz=pytz.timezone('Europe/Stockholm'))
Upvotes: 3