Python Date Format AM PM
Chapter:
Python
Last Updated:
14-05-2023 11:53:56 UTC
Program:
/* ............... START ............... */
from datetime import datetime
now = datetime.now()
formatted_date = now.strftime("%d-%m-%Y %I:%M:%S %p")
print(formatted_date)
/* ............... END ............... */
Output
Notes:
-
In this example, the strftime() function is called on the now datetime object with the format string "%d-%m-%Y %I:%M:%S %p". The %d, %m, and %Y are directives representing day, month, and year respectively. The %I directive represents the hour in 12-hour format, %M represents minutes, %S represents seconds, and %p represents the AM/PM indicator.
- When you run this code, it will display the current date and time in the specified format, including the AM/PM indicator.
- Here's an example output: "14-05-2023 02:30:15 PM"
- Note that the actual output will depend on the current date and time when you run the program.
Tags
Python date format am pm from string, Python Date Format AM PM, Python datetime format