You can download this code by clicking the button below.
This code is now available for download.
This function returns a formatted string of the current date, time, or datetime based on the input argument ('date', 'time', 'datetime').
Technology Stack : datetime, calendar
Code Type : Date and time formatting
Code Difficulty : Intermediate
def format_time(arg1, arg2, arg3):
from datetime import datetime
import calendar
if arg1 == 'date':
formatted_date = datetime.now().strftime('%Y-%m-%d')
return formatted_date
elif arg1 == 'time':
formatted_time = datetime.now().strftime('%H:%M:%S')
return formatted_time
elif arg1 == 'datetime':
formatted_datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
return formatted_datetime
else:
return None