Python Datetime Module:
|We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.|
(1) The Python datetime module provides a set of functions and methods for creating, manipulating, and formatting datetime objects.
(2) The datetime() method creates a datetime object and accepts the year, month, day, and optionally hour, minute, second, milliseconds, and time zone arguments.
(3) The datetime.now() method is used to see the current date and time.
(4) strftime()– The strftime() function allows datetime objects to be converted into custom-formatted strings. This function takes a format string as its input. This format string is made up of special characters beginning with the percent sign as shown below.
|%b||Month as locale’s abbreviated name.||Jan|
|%B||Month as locale’s full name.||January|
|%m||Month as a zero-padded decimal number.||05|
|%M||Minute as a zero-padded decimal number.||45|
|%y||Year without century as a zero-padded decimal number.||22|
|%Y||Year with century as a decimal number.||2022|
|%H||Hour (24-hour clock) as a zero-padded decimal number.||16|
|%I||Hour (12-hour clock) as a zero-padded decimal number.||08|
|%p||Locale’s equivalent of either AM or PM.||PM|