How to convert string into datetime in Python?

Posted by Editorial Staff | Updated on

Want to convert string into datetime in Python? Use the following Python example code. datetime.strptime is the main routine for parsing strings into datetimes. It can handle all sorts of formats, with the format determined by a format string you give it:

The resulting datetime object is timezone-naive.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers