Carbon::now() is not using UTC

Vahn Marty picture Vahn Marty · Nov 24, 2016 · Viewed 35.4k times · Source

I am from Philippines. If ever I will use Carbon::now(), it catches my machine time and not the UTC time.

My config/app.php is:

    'timezone' => 'UTC',

This is my code:

$log->dateRequest = Carbon::now();

If ever I will post a request at 9:00pm (Philippine time). It catches 21:00:00 , instead of 13:00:00 (from UTC).

Answer

Alexey Mezenin picture Alexey Mezenin · Nov 24, 2016

In one of you questions you mentioned that you need to use multiple timezones in your app. So, you can add timezone dynamically:

Carbon::now('UTC')

Or use setTimezone('UTC') method on existing date.