Regex for 24-Hour Time
This regex matches times in 24-hour format (HH:MM) where hours range from 00 to 23 and minutes range from 00 to 59. The 24-hour clock format is the international standard and is unambiguous unlike the 12-hour AM/PM format. It is commonly used in scheduling systems, timetables, military applications, and most programming contexts.
^([01]\d|2[0-3]):([0-5]\d)$ What is the regex pattern for 24-Hour Time?
The regex pattern for 24-Hour Time is ^([01]\d|2[0-3]):([0-5]\d)$. This regex matches times in 24-hour format (HH:MM) where hours range from 00 to 23 and minutes range from 00 to 59. The 24-hour clock format is the international standard and is unambiguous unlike the 12-hour AM/PM format. It is commonly used in scheduling systems, timetables, military applications, and most programming contexts. This pattern is commonly used for schedule validation and time input forms.
Test Examples
14:30 14:30 00:00 00:00 25:00 Common Uses
- ✓ Schedule validation
- ✓ Time input forms
- ✓ Log timestamp parsing
- ✓ Timetable systems
Variations
With seconds
^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$ Includes seconds as HH:MM:SS
12-hour format
^(0?[1-9]|1[0-2]):[0-5]\d\s?(AM|PM)$ Matches 12-hour time with AM/PM
With milliseconds
^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{3}$ HH:MM:SS.mmm format
Frequently Asked Questions
What is the difference between 24-hour and 12-hour time?
24-hour time runs from 00:00 to 23:59 and does not use AM/PM. 12-hour time runs from 12:00 AM to 11:59 PM. The 24-hour format is unambiguous and preferred in most technical contexts.
Does this match midnight as 00:00 or 24:00?
This pattern matches 00:00 but not 24:00. While 24:00 is technically valid in ISO 8601 to denote the end of a day, it is rarely used and this pattern follows the more common convention.
Can I validate time ranges with this regex?
Regex validates format, not ranges. To check if a time is between 09:00 and 17:00, parse the matched string and compare numerically.