How do you convert string to a strongly-typed datetime in Python?
Experience Level: Junior
Tags: Python
Answer
To convert a string to strongly-typed datetime, import the datetime module. Then call strptime() function with the format that defines how the parsing will be done.
Hint: strptime stands for string parse time.
Example:
from datetime import datetime
datetime_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
Related Python job interview questions
What does strftime stand for in Python?
Python JuniorWhat does strptime stand for?
Python JuniorHow do you break a long single-line method call to multiple lines?
Python JuniorHow do you split long method signature to multiple lines in the most efficient way?
Python JuniorHow do you split long line to multiple lines in Python?
Python Junior