Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top