7

Possible Duplicate:
How to parse ISO formatted date in python?

I have an isoformat datetime as a string like the example below -

'2011-05-31T04:35:33.127-05:00'

What is the best way convert it to a python datetime object? I came across some posts that tell how to get an isoformat string but not the other way round.

Thanks!!

Edit based on Yan's comment-

>>>import dateutil.parser
>>> d1='2011-05-31T04:35:33.127-05:00'
>>> d2=dateutil.parser.parse(d1)
>>> d2
datetime.datetime(2011, 5, 31, 4, 35, 33, 127000, tzinfo=tzoffset(None, -18000))

I need to get the datetime object for the local time represented by the original string. Since I do not know which timezone the input date was in, I cannot use the astimezon method. What will be the best way to get that? Thanks!!

0

1 Answer 1

0

There is an strptime function, just like in C. http://docs.python.org/library/datetime.html#datetime.datetime.strptime

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks letibee for your response, but unfortunately datetime.datetime.strptime does not work well for the isoformat date string. Thanks Yan, yes I want something like dateutil parser. I have edited my original question. Is there a way to the local time using tzoffset?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.