AM/PM to 24-Hour Time Converter
Convert 12-hour AM/PM time format to 24-hour (military) time instantly. Supports batch conversion, validation, and copy-to-clipboard.
| # | Input | 24-Hour Output | Status |
|---|
About
Incorrect time format conversion causes silent data corruption in databases, scheduling conflicts in APIs, and broken timestamp comparisons. The 12-hour clock with its AM/PM designator is ambiguous at the boundaries: 12:00 AM is midnight (00:00), not noon. Confusing these two values shifts records by exactly 12 hours. This converter parses input in hh:mm AM|PM format and outputs ISO-compliant HH:MM:SS 24-hour time. It validates hour range 1 - 12, minute range 00 - 59, and rejects malformed input rather than guessing intent.
Batch mode processes multiple lines simultaneously. The tool handles edge cases that trip up naive implementations: 12:30 PM stays 12:30:00, while 12:30 AM becomes 00:30:00. Limitation: this tool does not parse seconds or timezone offsets. It assumes local wall-clock time input.
Formulas
The conversion from 12-hour to 24-hour format applies a piecewise function on the hour component h based on the meridiem designator m:
Where h is the input hour (1 - 12), m is the meridiem (AM or PM), and H24 is the resulting hour in 24-hour notation (0 - 23). The minute component passes through unchanged. The output is zero-padded to two digits and seconds are appended as 00.
Input validation regex pattern: ^(\d{1,2}):(\d{2})\s*(AM|PM)$ with case-insensitive flag. Hour validated against range [1, 12], minutes against [0, 59].
Reference Data
| 12-Hour Input | 24-Hour Output | Common Name | Note |
|---|---|---|---|
| 12:00 AM | 00:00:00 | Midnight | Start of day |
| 12:30 AM | 00:30:00 | After midnight | Hour resets to 0 |
| 1:00 AM | 01:00:00 | Early morning | Direct mapping |
| 6:00 AM | 06:00:00 | Morning | Direct mapping |
| 11:59 AM | 11:59:00 | Late morning | Last AM minute |
| 12:00 PM | 12:00:00 | Noon | Hour stays 12 |
| 12:30 PM | 12:30:00 | After noon | Hour stays 12 |
| 1:00 PM | 13:00:00 | Afternoon | 1 + 12 |
| 5:00 PM | 17:00:00 | Evening | 5 + 12 |
| 6:45 PM | 18:45:00 | Early evening | 6 + 12 |
| 9:00 PM | 21:00:00 | Night | 9 + 12 |
| 11:59 PM | 23:59:00 | Late night | Last minute of day |
| 0:00 AM | Invalid - hour must be 1 - 12 | ||
| 13:00 PM | Invalid - hour exceeds 12 | ||
| 7:60 AM | Invalid - minutes exceed 59 | ||
Frequently Asked Questions
7:00 PM and 7:00PM are accepted. However, the meridiem designator itself (AM or PM) is required. Input like 7:00 alone is rejected as ambiguous.+05:00 or Z) because the input carries no timezone information. Append the offset manually if needed for full ISO 8601 compliance.