W3docs

Laravel Carbon: how to change timezone without changing the hour?

In Laravel, you can use the setTimezone method on a Carbon instance to change the timezone without changing the hour.

In Laravel, you can use the setTimezone method on a Carbon instance to change the timezone without changing the hour. Here's an example:

Example of using the setTimezone method on a Carbon instance in Laravel Carbon

<?php

$date = Carbon::now();

// current timezone
echo $date->timezone; // America/New_York

// change timezone without changing the hour
$date->setTimezone('Europe/Paris');

// new timezone
echo $date->timezone; // Europe/Paris

<div class="alert alert-info flex not-prose">Watch a course <span class="hidden md:block">Watch a video course</span> Learn object oriented PHP </div>

Note that the setTimezone method accepts a string argument that should be a valid timezone identifier, you can check all the valid timezone identifier in this link: https://www.php.net/manual/en/timezones.php