Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Created_at save with the wrong timezone

Tags:

laravel

I have a laravel app and i'm trying to save the users checkins and checkouts to my database

i have a model Checkins and i record it like created_at and updated_at

on my localhost it save with the right time for my timezome ( Egypt ), i tried to changed app.php file to the following

    |--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/

'timezone'        => 'EET',

it's working just fine on my localhost and save with the current right time, for the production it's save with UTC timezone

Also when i write in the production terminal the command date date, i get the following

Tue Mar 31 12:46:38 EET 2015

and i checked mysql for the timezone and i found it's getting the time from the system time

SELECT @@global.time_zone, @@session.time_zone;
SYSTEM

What's wrong here ?

UPDATE:

I created a php page with date('H:i:s'); and it's print the right time

like image 651
osos Avatar asked Mar 31 '15 10:03

osos


2 Answers

To set the timezone for your Laravel app, change the 'timezone' in your config/app.php

|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/

'timezone'        => 'America/Los_Angeles',

You can find the timezone you need here.

like image 78
Artur Grigio Avatar answered Nov 02 '22 13:11

Artur Grigio


You have to change yout time zone in config/app.php

Also as is said here you must run following commands for your time zone changes to be saved:

php artisan cache:clear php artisan view:clear php artisan config:cache

like image 26
batsz Avatar answered Nov 02 '22 12:11

batsz