If I have a string of timestamp, is there some python library that can identify the format of timestamp and give me a datetime object? Example of a string is:
Sat, 16 Jan 2016 07:50:17 GMT
Can you also give an example of how it can be done?
Use dateutil. You can install it with pip.
from dateutil.parser import parse
dt = parse('Sat, 16 Jan 2016 07:50:17 GMT')
print(dt)
print(type(dt))
Output
2016-01-16 07:50:17+00:00 <type 'datetime.datetime'>
dateutils source code might help.You can use strptime() for parsing the string to a datetime type object.
from datetime import datetime
date_str = "Sat, 16 Jan 2016 07:50:17 GMT"
date_obj = datetime.strptime(date_str, '%a, %d %b %Y %X %Z')
print type(date_obj)
Output:
<type 'datetime.datetime'>