strftime()` method is used to format the date and time in a specific format. strftime()` method :import datetime
# get current date and time
now = datetime.datetime.now()
# format date and time using strftime()
date_string = now.strftime("%d-%m-%Y %H:%M:%S")
# print the formatted date and time
print("Formatted date and time:", date_string)Formatted date and time: 27-04-2023 13:04:43datetime` module. We then get the current date and time using the `now()` method of the `datetime` class. strftime()` method to format the date and time in the desired format. In this case, we have used the format string `"%d-%m-%Y %H:%M:%S"`, which represents the day, month, year, hour, minute, and second in the desired format.print()` function.