Header Ads Widget

Program for change formate of time from 12 to 24 hours

In this program we change the time which is the 12 hour format into 24 hour format 


 Code:-


def change_formate(time):
t=time[-2:]
new_time=time[:-2]
t1 = int(time[:2])
if(t=="PM"):
t1=t1+12
new_time=str(t1)+time[2:-2]
elif t=="AM" and t1==12:
new_time="00"+time[2:-2]

print(new_time)
t=input("Enter time in formate 00:00:00 AM/PM\n")
change_formate(t)

Output:-


Enter time in formate 00:00:00 AM/PM
01:12:23 PM
13:12:23



Post a Comment

2 Comments