Pregunta

Perhaps I am missing something obvious, but does anyone know why the parser from dateutil fails to render the following hour correctly? (The hour should be 20 instead of 0.)

>>> from dateutil import parser
>>> parser.parse("20130501200439+01'00'")
datetime.datetime(2013, 5, 1, 0, 4, 39, tzinfo=tzoffset(None, 3600))

Add a T:

>>> parser.parse("20130501T200439+01'00'") # added T
datetime.datetime(2013, 5, 1, 0, 4, 39, tzinfo=tzoffset(None, 3600))

Add ignoretz:

>>> parser.parse("20130501T200439+01'00'", ignoretz=True) # ignore timezone
datetime.datetime(2013, 5, 1, 0, 4, 39)

Try a different hour:

>>> parser.parse("20130501T030439+01'00'") # should render hour as 3
datetime.datetime(2013, 5, 1, 0, 4, 39, tzinfo=tzoffset(None, 3600))
¿Fue útil?

Solución

The parser doesn't seem to accept the form of tz data in the string. Removing the single quotes seems to work:

>>> parser.parse("20130501200439+01'00'".replace("'", ""))
datetime.datetime(2013, 5, 1, 20, 4, 39, tzinfo=tzoffset(None, 3600))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top