0

I have a string '201502190759'. This represents 2015/02/19 at 7:59.

Is there a method within the python library that can convert '201502190759' into a datetime object or timestamp?

Liondancer
  • 15,721
  • 51
  • 149
  • 255

1 Answers1

1

Yep, datetime.datetime.strptime will do it.

>>> import datetime
>>> print(datetime.datetime.strptime('201502190759', '%Y%m%d%H%M'))
2015-02-19 07:59:00

The docs on the format modifiers are here.

mgilson
  • 300,191
  • 65
  • 633
  • 696