Given a time in 12-hour AM/PM format, convert it to military (24-hour) time.
Note : Midnight is 12:00:00 AM on a 12-hour clock and 00:00:00 on a 24-hour clock. Noon is 12:00:00 PM on 12-hour clock and 12:00:00 on 24-hour clock.
Input : 11:21:30 PM Output : 23:21:30 Input : 12:12:20 AM Output : 00:12:20
Approach : Whether the time format is 12 hours or not, can be found out by using list slicing. Check if last two elements are PM, then simply add 12 to them. If AM, then don’t add. Remove AM/PM from the updated time.
Below is the implementation :
- Program to convert time from 12 hour to 24 hour format
- Convert time from 24 hour clock to 12 hour clock format
- Find time when hour and minute hands superimpose
- Find a time for which angle between hour and minute hands is given theta
- Python | Pandas Period.hour
- Python | Pandas Series.dt.hour
- Python | Pandas Timestamp.hour
- Python | Pandas DatetimeIndex.hour
- Python | Pandas PeriodIndex.hour
- Time when minute hand and hour hand coincide
- Hour-glass Pattern
- Program to Convert Milliseconds to a Date Format in Java
- Python program to find difference between current time and given time
- Python program to print the dictionary in table format
- Wand - Convert image format