Hello, laravel web developers! In this article, we'll see how to convert UTC time to local time in laravel 11. Here, we'll use the carbon parse function to convert local time in laravel 11. Use Carbon's setTimezone() method in Laravel 11 to convert any UTC time to your local setting.
Sometimes, we need to convert time to local time zones for our projects. So, we'll convert UTC time zone to specific local time zones.
Laravel 11 Convert UTC time to local time
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$time = Carbon::parse('2024-06-29 21:20:50')
->setTimezone('Asia/Kolkata')
->toDateTimeString();
dd($time);
}
}
2024-06-30 02:50:50
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$time = Carbon::now()
->setTimezone('Asia/Kolkata')
->toDateTimeString();
dd($time);
}
}
2024-06-29 19:20:10
You might also like:
In this small artical we will see how to force redirect http to https in laravel, Here i will show you two method in&nbs...
Aug-11-2021
In this artical we will see laravel 9 yajra datatable example. As we all used datatable on our backend side project, Her...
Mar-10-2022
When working on a Laravel application, you may encounter scenarios where Python's robust libraries for data transfor...
Nov-26-2024
In the dynamic realm of modern web development, ensuring that APIs are well-documented, easy to comprehend, and seamless...
Aug-18-2023