2

I have a following datetime:

d1 = 2015-03-21 14:50:54.0.

While doing datetime.strptime(d1, "%Y-%m-%d %H:%M:%S") I get an error that ValueError: unconverted data remains: .0. How can I add milliseconds to the time? If it not possible then how can I remove milliseconds from d1?

Bob
  • 10,427
  • 24
  • 63
  • 71

1 Answers1

2

Use %f to grab the milliseconds part of the time string:

>>> out = datetime.strptime(d1, "%Y-%m-%d %H:%M:%S.%f")
rayryeng
  • 102,964
  • 22
  • 184
  • 193