2

I want a datetime object, but I have strings in this format:

2010-10-06T08:12:41Z

How do I turn that into a datetime object?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • Search. That's how it's done. Your question has been asked. And asked. – S.Lott Oct 06 '11 at 19:16
  • 1
    possible duplicate of [Retrieving a date from a complex string in Python](http://stackoverflow.com/questions/7070175/retrieving-a-date-from-a-complex-string-in-python) – S.Lott Oct 06 '11 at 19:16
  • 1
    Also http://stackoverflow.com/questions/2265357/parse-date-and-format-it-using-python and http://stackoverflow.com/questions/1713594/parsing-dates-and-times-from-strings-using-python are pretty good duplicates of this. – S.Lott Oct 06 '11 at 19:18

2 Answers2

6
from datetime import datetime
print datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%SZ')

it's in the docs

knitti
  • 6,817
  • 31
  • 42
2
import datetime
datetime.datetime.strptime("2010-10-06T08:12:41Z", "%Y-%m-%dT%H:%M:%SZ")
Kasapo
  • 5,294
  • 1
  • 19
  • 21