Frage

How to include microseconds to datetime, for example:

import datetime

dt = datetime.datetime.strptime('2010-08-30 15:02:55.730', '%Y-%m-%d %H:%M:%S')

>>> ValueError: unconverted data remains: .730

I want to have microseconds too. What should format string look like? What is the placeholder for microseconds?

War es hilfreich?

Lösung

dt = datetime.datetime.strptime('2010-08-30 15:02:55.730', '%Y-%m-%d %H:%M:%S.%f')

you can look at:

http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top