Problem Statement
You’re given time in 12-hour format, you need to convert the time to 24-hour format (military time).
Example 1: Let time = 10:20:30 PM
Time in 24-hour format = 22:20:30
Thus the output is 22:20:30
Example 2: Let time = 06:10:00 AM
Time in 24-hour format = 06:10:00
Thus the output is 06:10:00
Example 3: Let time = 12:55:10 AM
Time in 24-hour format = 00:55:10
Thus the output is 00:55:10
Conditions for 12-Hour and 24-Hour Time Format:
Midnight: Midnight is 12:00:00 AM in 12-hour time format and 00:00:00 in 24-hour time format. Noon: Noon is 12:00:00 PM in 12-hour time format and 12:00:00 in 24-hour time format.
C++ Program to Convert Time in 12-Hour Format to 24-Hour Format
Below is the C++ program to convert time in 12-hour format to 24-hour format:
Output:
Python Program to Convert Time in 12-Hour Format to 24-Hour Format
Below is the Python program to convert time in 12-hour format to 24-hour format:
Output:
JavaScript Program to Convert Time in 12-Hour Format to 24-Hour Format
Below is the JavaScript program to convert time in 12-hour format to 24-hour format:
Output:
C Program to Convert Time in 12-Hour Format to 24-Hour Format
Below is the C program to convert time in 12-hour format to 24-hour format:
Output:
Learn More About Common Algorithms
Algorithms are the core of programming. They’re integral in helping to solve any and all programming problems. You must know about the most common algorithms like Dijkstra’s Algorithm, Merge Sort, Quicksort, Depth First Search, Breadth-First Search, Binary Search, etc. if you want to be the most efficient programmer you can be.