Skip to content

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.

Pattern
^([01]\d|2[0-3]):([0-5]\d)$
Test this pattern in the Regex Tester →

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

Match
14:30
Matches: 14:30
Match
00:00
Matches: 00:00
No Match
25:00

Common Uses

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.

Related Patterns

ISO 8601 DateTime

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[...

Date (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[...

Date (MM/DD/YYYY)

^(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/\...

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →