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
  • 14,518
  • 43
  • 138
  • 238

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
  • 283,004
  • 58
  • 591
  • 667