Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

viktor3177's avatar

Time format AM/PM

My problem is that the time is displayed in 24 hour format. How to convert to standard time with am/pm? The site is powered by Laravel.

0 likes
2 replies
tykus's avatar

You can use time format string like this:

g:i a
  • g for 12-hour format of an hour without leading zeros
  • i for minutes with leading zeros
  • a for lowercase Ante meridiem and Post meridiem

https://www.php.net/manual/en/datetime.format.php

If working with a Carbon instance:

$date->format('g:i a')
kokoshneta's avatar

Just to get things straight, 24-hour time is the international standard. 12-hour time with AM/PM is nonstandard in virtually all international contexts, and only standard nationally in about a dozen countries.

That said, the easiest way to format time from a Carbon instance in a way that is naturally to most people is to use the macro-format LT (or LTS if you want seconds as well). If your locale is set to English, that will result in h:mm(:ss) A (= PHP native format g:i(:s) A), so for example 5:04 PM. If you change your locale to French, where no one would ever write time like that, it becomes HH:mm, for example 17:04, etc.

$date->format('LT');
// or
$date->format('LTS');

You can read more about macro-formats in the Carbon docs.

1 like

Please or to participate in this conversation.