Laravel Carbon Time Format AM PM Example Code

Hello Artisan,

This tutorial will give you an example of laravel carbon convert am pm. you can understand a concept of laravel carbon am pm. We will look at an example of convert time to am pm in laravel carbon. I would like to share with you how to convert time into am and pm in laravel.

You can use these tips with laravel 6, laravel 7, laravel 8 and laravel 9 versions.

Laravel carbon provide format() method to convert time to am and pm. we will use “g:i A” format as argument to convert am and pm time. so let’s see the example code below:

Example:

app/Http/Controllers/DemoController.php

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use CarbonCarbon;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$now = Carbon::now();

$time = $now->format('g:i A');

dd($time);

}

}

Output:

4:08 AM

I hope it can help you…

Leave a Comment