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, laravel 9 and laravel 10 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 App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Carbon diffForHumans() Example
- Laravel Carbon createFromFormat() Example
- Laravel Carbon Check Date is in Past Date Code
- Carbon Get First Day of Specific Month Example
- Laravel Carbon Convert String to Date Example
- Laravel Carbon Get Previous Month Example
- Laravel Carbon Check Current Date Between Two Dates Example
- Laravel Carbon Subtract Seconds Example
- Laravel Carbon Subtract Minutes Example
- Laravel Carbon Subtract Hours Example
- Laravel Carbon Subtract Days to Date Example
- Laravel Carbon Add Days to Date Example
- Laravel Calculate Age from Date of Birth Example