开发者

convert an isoformat string to python datetime object [duplicate]

This question already has answers here: Closed 11 years ago.

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 开发者_如何学JAVAwhich timezone the input date was in, I cannot use the astimezon method. What will be the best way to get that? Thanks!!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜