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 article, we will see how to create a candlestick chart in laravel 9 using highcharts. A candlestick is a ty...
Oct-06-2022
In this guide, I’ll show you how to connect Laravel queues with Python to handle resource-heavy tasks such as data...
Nov-12-2024
In this article, we will see laravel 9 many to many relationship example. Also, you can use many to many relationsh...
Apr-03-2022
In this article, we'll learn how to locate elements using data-attribute values. We can do this using jQuery and CSS...
Jul-11-2022