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. Here's an example:

<?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

Watch a course Learn object oriented PHP

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