strptime don't take microseconds in python 2.x. Here is a quickway to add them to a datetime object.
1 >>> from datetime import datetime
2 >>> from time import strptime
3 >>> date_str='2007-11-08 16:17:17.375000'
4 >>> d = datetime(*strptime(date_str[:19],"%Y-%m-%d %H:%M:%S")[0:6])
5 >>> d = d.replace(microsecond=eval(date_str[20:]))
6 >>> print d
7 2007-11-08 16:17:17.375000
Many file formats and standards use the ISO 8601 date format (e.g. 2007-01-14T20:34:22+00:00) to store dates in a neutral, unambiguous manner. Here is a way to convert them in datetime format
1 >>> from datetime import datetime
2 >>> from time import strptime
3 >>> s="2007-10-01T02:06:54Z"
4 >>> datetime(*strptime(s,"%Y-%m-%dT%H:%M:%SZ")[0:6])
5 datetime.datetime(2007, 10, 1, 2, 6, 54)
Pages : 1