Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I convert: u'2012-11-07T13:25:10.703Z' to Python datetime?

EDIT

I intend to use something like this:

>>> from datetime import datetime
>>> datetime.strptime('2011-03-07','%Y-%m-%d')
datetime.datetime(2011, 3, 7, 0, 0)

but how can I change the second argument to accommodate my date format?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
132 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use datetime.datetime.strptime:

datetime.datetime.strptime(u'2012-11-07T13:25:10.703Z', '%Y-%m-%dT%H:%M:%S.%fZ')

Result:

datetime.datetime(2012, 11, 7, 13, 25, 10, 703000)

See the description of the strptime behaviour.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...