One possible method to change 24 hour format to 12 hour format without relying on import modules is:
time_str = input("Enter a time in 24 hour format (hh:mm:ss): ")
time_parts = time_str.split(":")
hour = int(time_parts[0])
minute = int(time_parts[1])
second = int(time_parts[2])
if hour > 12:
hour -= 12
if hour < 12:
meridian = "AM"
else:
meridian = "PM"
print("The time in 12 hour format is: {:02d}:{:02d}:{:02d} {}".format(hour, minute, second, meridian))
This method assumes that the input time is valid and in the correct format (hh:mm:ss), and that the hour is a number between 0 and 23. It also assumes that the output time should be in the format hh:mm:ss AM/PM.
Asked: 2022-02-10 11:00:00 +0000
Seen: 14 times
Last updated: Jan 20 '22