Convert String to Datetime in Python
If you have a string
and want to create a Datetime
object out of it in Python, then you can use the Datetime Parse Time method, as follows:
There are 2 very useful functions of datetime
, namely:
strptime
– Parse a stringstrftime
– Format a string
A common format you may be looking for is:
%Y-%m-%d %H:%M:%S