Given a time in a 24-hour clock (military time), convert it to 12-hour clock format.
Note: Midnight is 00:00:00 on a 24-hour clock and 12:00:00 AM on a 12-hour clock. Noon is 12:00:00 on 24-hour clock and 12:00:00 PM on 12-hour clock.
A string will be given of the format hh:mm:ss and output should be in the format hh:mm:ss AM or hh:mm:ss PM in 12hour clock. Here hh represents hour, mm represents minutes and ss represents seconds.
Input : 17:35:20 Output : 5:35:20 PM Input : 00:10:24 Output : 12:10:24 AM
The approach to solving this problem requires some observations. First that the minutes and seconds will be same in both the cases. The only change will be in the hours and according to that Meridien will be appended to the string.
For hours, first convert it from string to int datatype, then take its modulo with 12 and that will be our hours in 12-hour format. Still, there will be a case when hour becomes 00 i.e (12 or 00 in 24-hour format) which we need to handle separately.
Below is the implementation of above approach:
- Possible number of Rectangle and Squares with the given set of elements
- Check if a point is inside, outside or on the parabola
- Program to find N-th term of series 3, 5, 33, 35, 53....
- Program to find the product of ASCII values of characters in a string
- Check if a point is inside, outside or on the ellipse
- Program to find Nth term of the series 2, 4, 3, 4, 15...
- Program to print Kite Pattern
- Count Numbers with N digits which consists of odd number of 0's
- Program for n-th even number
- Program to find the Radius of the incircle of the triangle
- C/C++ program to make a simple calculator
- Difference between continue and break statements in C++
- Program for Deadlock free condition in Operating System
- Degree of a Cycle Graph
- Program to find the value of sin(nΘ)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SURENDRA_GANGWAR