5

Facebook returns 'created_time' in this format:

2012-07-23T08:52:04+0000

I want to convert this timestamp to a normal Python DateTime object.

Nazim Zeeshan
  • 713
  • 1
  • 12
  • 20

2 Answers2

7

Have you tried dateutil

It's extremely easy to use

import dateutil.parser as dateparser
dateparser.parse('2012-07-23T08:52:04+0000')

dateutil is very helpful to deal with timezone info, and it can handle lots of time formats.

xiaowl
  • 5,177
  • 3
  • 27
  • 28
  • Discussion on using dateutil in python2: http://stackoverflow.com/questions/1101508/how-to-parse-dates-with-0400-timezone-string-in-python – Vladimir Jul 28 '12 at 11:59
2
s = "2005-12-06T12:13:14"
from datetime import datetime
from time import strptime
print datetime(*strptime(s, "%Y-%m-%dT%H:%M:%S")[0:6])
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79