String with time with decimal second
Tell me I have a formatted string HHMMSS.SS
, how do I convert this to a time object?
This is how I thought you would do it:
import time
time.strptime(timestring, '%H%M%S')
However, it %S
does not take into account fractions of seconds according to the time documentation .
+3
Richard
source
to share
1 answer
You will need to use% f
time.strptime('26/01/12 23:50:32.123', '%d/%m/%y %H:%M:%S.%f')
Using datetime would be correct.
>>> from datetime import datetime
>>> a = datetime.strptime('26/01/12 23:50:32.123', '%d/%m/%y %H:%M:%S.%f')
>>> a.microsecond
+14
ganesh
source
to share