0% found this document useful (0 votes)
2 views

Java RECHECK 3

This document contains a Python script that provides various date and time formatting options. Users can select from four different formats to display the current date and time, or exit the program. The script utilizes the datetime module to retrieve the current date and time and formats it based on user input.

Uploaded by

cshinde000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java RECHECK 3

This document contains a Python script that provides various date and time formatting options. Users can select from four different formats to display the current date and time, or exit the program. The script utilizes the datetime module to retrieve the current date and time and formats it based on user input.

Uploaded by

cshinde000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

from datetime import datetime

def display_format_1(dt):

# Display: day, month(abbreviated), year

return dt.strftime("%d, %b, %Y")

def display_format_2(dt):

# Display: day, month(full month), day-of-week(abbreviated)

return dt.strftime("%d, %B, %a")

def display_format_3(dt):

# Display: day, month(two-digits), hours, minutes and seconds

return dt.strftime("%d, %m, %H:%M:%S")

def display_format_4(dt):

# Display: day, hours(in 24hrs), minutes and am/pm

return dt.strftime("%d, %I:%M %p")

def main():

now = datetime.now()

menu = """

Please select an option:

1. Display day, month(abbreviated), year

2. Display day, month(full month), day-of-week(abbreviated)

3. Display day, month(two-digits), hours, minutes and seconds

4. Display day, hours(in 24hrs), minutes and am/pm

0. Exit

"""

while True:
print(menu)

choice = input("Enter your choice: ")

if choice == '1':

print("Formatted Date/Time:", display_format_1(now))

elif choice == '2':

print("Formatted Date/Time:", display_format_2(now))

elif choice == '3':

print("Formatted Date/Time:", display_format_3(now))

elif choice == '4':

print("Formatted Date/Time:", display_format_4(now))

elif choice == '0':

print("Exiting...")

break

else:

print("Invalid choice, please try again.")

if __name__ == "__main__":

main()

You might also like