Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > datetime.strptime w/ non-UTC and non-local TZs?

Reply
Thread Tools

datetime.strptime w/ non-UTC and non-local TZs?

 
 
Artur Ergashev
Guest
Posts: n/a
 
      08-15-2011
I was hoping somebody give me some clarity on how datetime.strptime is
supposed to work, I'm thinking this is a bug, but wanted to see if the
community has any ideas before I submit a bug to the python tracker.
For reference I am in the CDT timezone...

>>> from datetime import datetime
>>> date_utc = "Sun Jul 24 02:54:11 UTC 2011"
>>> date_local = "Sun Jul 24 02:54:11 CDT 2011"
>>> date_other = "Sun Jul 24 02:54:11 PDT 2011"
>>> print datetime.strptime(date_utc, '%a %b %d %H:%M:%S %Z %Y')

2011-07-24 02:54:11
>>> print datetime.strptime(date_local, '%a %b %d %H:%M:%S %Z %Y')

2011-07-24 02:54:11
>>> print datetime.strptime(date_other, '%a %b %d %H:%M:%S %Z %Y')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Sun Jul 24 02:54:11 PDT 2011' does not match
format '%a %b %d %H:%M:%S %Z %Y'

The format is correct, and it can parse UTC (as mentioned in the
documentation), and it can parse CDT (which is my current time zone),
but using another timezone causes it to fail. Trying to parse the
failing timezone on a computer set on that timezone works correctly.
The documentation seems to indicate that parsing non-UTC TZs isn't
guaranteed to work, but in that case the exception is non-clear
(perhaps there's no elegant solution here).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments