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.
Converting timestamp to datetime We may use the datetime module's fromtimestamp() method to convert the timestamp back to a datetime object. It returns the POSIX timestamp corresponding to the local date and time, as returned by time. time().
You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.
For this, we will use the strptime() method and Pandas module. This method is used to create a DateTime object from a string. Then we will extract the date from the DateTime object using the date() function and dt. date from Pandas in Python.
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.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With