Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pranam's avatar

Carbon now showing same date and time in all timezone.

Hello, I am trying to get the current time in my local Timezone using carbon package but I came to an issue that Carbon::now(); is showing same timezone if I try to change the timezone. My global config timezone is in default UTC 'timezone' => 'UTC', . It is a serious issue, what is happening I don't know. Can anyone help me out?

use Carbon\Carbon;

Route::get('/carbon', function () {
    return response()->json([
        "timezonetest1" => Carbon::now('GMT+8'),
        "utc" => Carbon::now('UTC'),
        "now" => Carbon::now(),
        "london" => now('Europe/London'),
        "kolkata" => now()->tz('Asia/Kolkata'),
        "Chicago" => Carbon::now()->setTimezone('America/Chicago'),
    ], 200);
});

My Json Response Output

{
  "timezonetest1": "2023-05-17T05:22:20.789508Z",
  "utc": "2023-05-17T05:22:20.789518Z",
  "now": "2023-05-17T05:22:20.789523Z",
  "london": "2023-05-17T05:22:20.789540Z",
  "kolkata": "2023-05-17T05:22:20.789546Z",
  "Chicago": "2023-05-17T05:22:20.789555Z"
}
0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Because you are always dealing with the same Carbon instance.

When these are converted to json, they all end up with whatever timezone was applied last.

One option is to extract the time as a string before moving to the next value, eg

    "timezonetest1" => Carbon::now('GMT+8')->toIso8601String(),
    "utc" => Carbon::now('UTC')->toIso8601String(),
    "now" => Carbon::now()->toIso8601String(),
    "london" => now('Europe/London')->toIso8601String(),
    "kolkata" => now()->tz('Asia/Kolkata')->toIso8601String(),
    "Chicago" => Carbon::now()->setTimezone('America/Chicago')->toIso8601String(),

gives

{
  "timezonetest1":"2023-05-17T21:03:30+08:00",
  "utc":"2023-05-17T13:03:30+00:00",
  "now":"2023-05-17T13:03:30+00:00",
  "london":"2023-05-17T14:03:30+01:00",
  "kolkata":"2023-05-17T18:33:30+05:30",
  "Chicago":"2023-05-17T08:03:30-05:00"
}
1 like
Pranam's avatar

@Snapey Thank You I did exactly the same like yours or another one is Carbon::now()->toDateTimeString() and it is working as expected. Thanks again Sir.

Please or to participate in this conversation.