Given a time in the format of hh:mm (12-hour format) 0 < hh < 12, 0 <= mm < 60. The task is to convert it into words as shown:
Input : h = 5, m = 0 Output : five o' clock Input : h = 6, m = 24 Output : twenty four minutes past six
Corner cases are m = 0, m = 15, m = 30 and m = 45.
6:00 six o'clock 6:10 ten minutes past six 6:15 quarter past six 6:30 half past six 6:45 quarter to seven 6:47 thirteen minutes to seven
The idea is to use if-else-if statement to determine the time in words. According to above given example, on the basis of minutes we can categories time in words into 8, that are minutes equal to 0, 15, 30, 45, 1, 59 and in range less than 30 or greater than 30. Check the value of minutes and print accordinly.
Below is implementation of this approach:
twenty four minutes past six
This article is contributed by Anuj Chauhan. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Convert timestamp to readable date/time in PHP
- Python program to convert time from 12 hour to 24 hour format
- Program to convert time from 12 hour to 24 hour format
- Convert time from 24 hour clock to 12 hour clock format
- Time difference between expected time and given time
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Program to find the time after K minutes from given time
- Program to print the given digit in words
- Reorder the position of the words in alphabetical order
- Python | Scramble words from a text file
- Python program to print even length words in a string
- Add given n time durations
- Program to Convert Radian to Degree
- Convert String to Date in Java
- Program to convert Degree to Radian
- Program to Convert Hexadecimal Number to Binary
- Program to convert centimeter into meter and kilometer
- Program to convert Centimeter to Feet and Inches
- Program to convert speed in km/hr to m/sec and vice versa
- Program to Convert Km/hr to miles/hr and vice versa