像这样显示当前时区 +03:00 in Laravel

Display current timezone like this +03:00 in Laravel

$timezone = Carbon::now()->format('e'); // Asia/Riyadh

我想打印 +03:00 而不是 Asia/Riyadh

你可以用这个

$timezone = now()->format('P')

引用链接

https://www.php.net/manual/en/datetime.format.php

$timezone = Carbon::now()->format('P');

https://www.php.net/manual/en/datetime.format.php

From the docs:

echo Carbon::now()->tz->toOffsetName(); // +03:00

Or using CarbonTimeZone:

$tz = new CarbonTimeZone('Asia/Riyadh');
echo $tz->toOffsetName(); // +03:00

如果您正在使用现有的 Carbon 对象:

echo $tz->toOffsetName($date); // +03:00