Say I have a string with format 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%S
does not take take into account fractions of seconds according to the time documentation.
You will have to use %f
time.strptime('26/01/12 23:50:32.123', '%d/%m/%y %H:%M:%S.%f')
Use of datetime will be right
>>> from datetime import datetime
>>> a = datetime.strptime('26/01/12 23:50:32.123', '%d/%m/%y %H:%M:%S.%f')
>>> a.microsecond
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