C Program to convert 24 Hour time to 12 Hour time
In this tutorial, we will write a program that will convert a given time of 24-hour format to a 12-hour format.
The time will be given in the format of - Hours: Minutes: Seconds
For example -
Input : 20:35:20
Output : 8:35:20 PM
Input : 00:15:40
Output : 12:15:40 AM
The midnight in 24-hour clock format is 00:00:00 and in 12-hour format is 12:00:00. Now we need to observe that the minutes and seconds in both the observations are the same. There is a change in hours only when there is a change in the meridian.
To check hours we will first convert the input string of hours into an integer. After changing it into integer we will modulo the hour with 12 and that will be in the 12-hour format.
The case when there is 00 in the hour will be calculated as a separate case.
C code Implementation
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week