FAQ
I was trying to parse a date string containing "EDT" time zone

eg: 'Mon Jun 20 14:00:57 EDT 2011'

I tried:

datetime.strptime('Mon Jun 20 14:00:57 EDT 2011', '%a %b %d %H:%M:%S %Z %Y')

But I get error

Search Discussions

  • Ben Finney at Jun 21, 2011 at 4:12 am

    Junaid P V <junu.pv at gmail.com> writes:

    I tried:

    datetime.strptime('Mon Jun 20 14:00:57 EDT 2011', '%a %b %d %H:%M:%S %Z %Y')

    But I get error
    When reporting that you get an error, please give the full error and
    traceback.


    My mind reading skills are telling me, though, that you're getting a
    ValueError because you're trying to parse a timezone that is unknown to
    the ?time.strptime? function. See its documentation for why
    <URL:http://docs.python.org/library/time.html#time.strptime>.

    --
    \ ?Give a man a fish, and you'll feed him for a day; give him a |
    `\ religion, and he'll starve to death while praying for a fish.? |
    _o__) ?Anonymous |
    Ben Finney
  • Junaid P V at Jun 21, 2011 at 6:09 pm
    Thanks,

    My script should be platform independent, so I think filtering out time zone info is better.
  • Tim Roberts at Jun 21, 2011 at 5:52 am

    Junaid P V wrote:
    I was trying to parse a date string containing "EDT" time zone

    eg: 'Mon Jun 20 14:00:57 EDT 2011'

    I tried:

    datetime.strptime('Mon Jun 20 14:00:57 EDT 2011', '%a %b %d %H:%M:%S %Z %Y')

    But I get error
    Right, because strptime doesn't support %Z. You'll have to handle that
    yourself and remove it before conversion.
    --
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.
  • Ben Finney at Jun 21, 2011 at 6:10 am

    Tim Roberts <timr at probo.com> writes:

    Right, because strptime doesn't support %Z.
    Au contraire:

    Support for the %Z directive is based on the values contained in
    tzname and whether daylight is true. Because of this, it is
    platform-specific except for recognizing UTC and GMT which are
    always known (and are considered to be non-daylight savings timezones).

    <URL:http://docs.python.org/library/time.html#time.strptime>

    --
    \ ?Human reason is snatching everything to itself, leaving |
    `\ nothing for faith.? ?Saint Bernard, 1090?1153 |
    _o__) |
    Ben Finney
  • Tim Roberts at Jun 23, 2011 at 3:55 am

    Ben Finney wrote:
    Tim Roberts <timr at probo.com> writes:
    Right, because strptime doesn't support %Z.
    Au contraire:

    Support for the %Z directive is based on the values contained in
    tzname and whether daylight is true. Because of this, it is
    platform-specific except for recognizing UTC and GMT which are
    always known (and are considered to be non-daylight savings timezones).
    I do keep forgetting that Python's strptime does not just pass through to
    the C library. C's strptime does not support %Z.
    --
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.
  • Miki Tebeka at Jun 21, 2011 at 7:26 pm
    You might consider trying dateutil.parser.parse (http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 21, '11 at 2:56a
activeJun 23, '11 at 3:55a
posts7
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase