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

Abdullah_Iftikhar's avatar

How to get Current time with carbon now and also display in 12 hours format?

Hello!

I want to convert Carbon::now()->toTimeString() in AM/PM.

Can anyone help me with it?

0 likes
3 replies
sr57's avatar

Carbon::now()->isoFormat('Do MMMM HH:MM a');

or

Carbon::now()->isoFormat('Do MMMM HH:MM A');

AcidDiz's avatar

To convert to a AM PM string just don't call toTimeString()..

$time = Carbon::now();

$time->format('Y/m/d g:i:s A');

echo gettype($time); //Return string

Please or to participate in this conversation.