Python Example | Convert a String to Datetime

This python example code will introduce us how to convert a python string to datetime object.

import datetime

dt_string = "2020-12-18 3:11:09" 
format = "%Y-%m-%d %H:%M:%S"
dt_object = datetime.datetime.strptime(dt_string, format)
print("Datetime: ", dt_object)
print("Minute: ", dt_object.minute)
print("Hour: ", dt_object.hour)
print("Second: ", dt_object.second)