This program demonstrates how to use the strptime() method from the datetime module to convert a date string into a datetime object. The program first imports the datetime module, which provides classes for working with dates and times
Then, the strptime() method is used to convert a date string into a datetime object. The strptime() method takes two arguments - the first argument is the date string to be converted, and the second argument is a string that specifies the format of the date string.
In this program, the date string "June 8 2014 10:30:54 AM" is converted into a datetime object by specifying the format of the date string as "%B %d %Y %I:%M:%S %p", which means:
The resulting datetime object is then printed to the console.
from datetime import datetime d = datetime.strptime("June 8 2014 10:30:54 AM", "%B %d %Y %I:%M:%S %p") print(d)
2014-06-08 10:30:54
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions