1

This is a real stranger, when return the current time with Carbon, this is return ever time as UTC for me. I do not understand why if I config as Europe/Madrid everything.

Example:

return Carbon::now() 
The result is 2020-07-06 14:30:00

But is:

dd(Carbon::now())

The result is 2020-07-06 16:30:00

I not understand why.

My file app.php

'timezone' => 'Europe/Madrid',

And when load a model for example user

$user = User::find(1);

The created_at and updated_at return

2020-06-07 14:35:00

But in database the value saved is

2020-06-07 16:35:00

enter image description here

Alexd2
  • 1,044
  • 2
  • 15
  • 28

1 Answers1

1

Carbon uses the default DateTime PHP object. You can set custom timezone as :

$date = Carbon::createFromFormat('Y-m-d H:i:s', $tz, 'Europe/Madrid');

In the AppServiceProvider.php you can add the php functionality to alter the timestamp for the whole project :

public function boot()
{
    Schema::defaultStringLength(191);
    date_default_timezone_set('Europe/Madrid');
}
STA
  • 30,729
  • 8
  • 45
  • 59