Staaarter

Convert 12hr Clock to 24hr

Parses one or more 12-hour clock times, written as H:MM AM/PM or H:MM:SS AM/PM, one per line, and converts each into 24-hour "military" time, handling the 12 AM and 12 PM edge cases correctly. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
clock-formatconversion

Overview

Introduction

Times written in familiar AM/PM format need converting to 24-hour form before they can feed into logs, APIs, or systems that expect unambiguous military time.

This tool performs that conversion instantly, correctly handling the 12 AM and 12 PM edge cases that a naive add-or-subtract-12 approach gets wrong.

What Is Convert 12hr Clock to 24hr?

A 12-hour-to-24-hour clock format converter that accepts H:MM AM/PM or H:MM:SS AM/PM and returns the equivalent 24-hour string.

It is a pure text-format converter, it does not touch timezones or calendar dates, only the way a single clock time is written.

How Convert 12hr Clock to 24hr Works

Each line is validated as a 12-hour time with an hour from 1 to 12 and an AM or PM label, then the hour is reduced modulo 12 to get its 24-hour base.

If the label is PM, 12 is added to that base, giving the correct 24-hour hour; a leading zero is added when needed.

When To Use Convert 12hr Clock to 24hr

Use it when you have a time written in familiar AM/PM format and need it in 24-hour form for a form field, API, or configuration file.

For the reverse direction, use Convert 24hr Clock to 12hr instead.

Features

Advantages

  • Correctly handles the 12 AM and 12 PM edge cases, a common source of manual conversion errors.
  • Converts multiple times at once, one per line.
  • Accepts AM/PM labels in any letter case and hours with or without a leading zero.

Limitations

  • Only accepts strict H:MM AM/PM or H:MM:SS AM/PM clock times, it does not parse full date-time strings.
  • Does not perform any timezone conversion, the output is the same instant in the same timezone as the input.

Examples

Converting an afternoon time

Input

2:30 PM

Output

14:30

2:30 PM in 12-hour time is 14:30 in 24-hour time.

Converting midnight

Input

12:00 AM

Output

00:00

12:00 AM is written as hour 12 in 12-hour time but hour 0 in 24-hour time.

Best Practices & Notes

Best Practices

  • Double-check 12 AM and 12 PM conversions manually the first few times, since they're the most common source of off-by-twelve errors.
  • Include the seconds field in the input whenever precision to the second matters, it carries through to the output unchanged.

Developer Notes

The parser uses `/^(1[0-2]|0?[1-9]):([0-5]\d)(?::([0-5]\d))?\s*([AaPp][Mm])$/`, then computes `hours12 % 12` as the 24-hour base and adds 12 when the label is PM, padding the result to two digits, all as plain string and number logic with no Date object involved.

Convert 12hr Clock to 24hr Use Cases

  • Converting a user-entered AM/PM appointment time into 24-hour format for storage
  • Preparing 24-hour timestamps for a system or API that rejects AM/PM notation
  • Normalizing mixed-format schedule data into consistent military time

Common Mistakes

  • Assuming 12 PM converts to "24:00" or that 12 AM converts to "12:00", both are handled specially rather than by a plain add-12 rule.
  • Omitting the AM/PM label entirely, which fails validation since the format requires it to disambiguate the hour.

Tips

  • Paste an entire list of 12-hour times at once, each line converts independently.
  • Use Convert 24hr Clock to 12hr to reverse the conversion and verify a result.

References

Frequently Asked Questions