I have the timestamp format such as "2014-01-06T00:39:45.001+0000" but I don't know exactly what this timestamp format is. So I can't convert it to datetime as I desired.
How can I convert it with Python?
I have the timestamp format such as "2014-01-06T00:39:45.001+0000" but I don't know exactly what this timestamp format is. So I can't convert it to datetime as I desired.
How can I convert it with Python?
>>> import dateutil.parser
>>> dateutil.parser.parse("2014-01-06T00:39:45.001+0000")
datetime.datetime(2014, 1, 6, 0, 39, 45, 1000, tzinfo=tzutc())
You can parse dates and times in arbitrary formats using datetime.strptime(date_string, format)
, with the grammar for defining format
presented here.
In this case:
format = "%Y-%m-%dT%H:%M:%S.%f%z"
Note: %z
is not supported before Python 3.2 for the .strptime()
method.