After inserted record into database, created_at
timestamp not display right time, it late 2h from server.... Also If i type into mysql SELECT NOW()
it show right time, any idea what is problem?
Edit..
It take date from Carbon
class... any idea how to change it?
The default timezone
for laravel is UTC
which is located in config/app.php
file.
If you want to change the timezone
to your preferred timezone
, choose your preferred timezone
from this list or from this list and replace the UTC
with your chosen timezone.
A few notes. As per the comments here, to be precise, the last 3 comments: You should not change the default values.
Storing dates of different
timezones
in data source of a same application (by changing thetimezone
in config for current user & letting Laravel handle it from there on) is just asking for trouble & is a bad design. You will lose data integrity. What will happen when a user changestimezone
? You'll update all the dates in the database for that user?Store dates for all users as UTC (or any other timezone of your choosing, just select one & stick to it). Laravel already uses the excellent Carbon library, use it to convert dates from your
timezone
(in which they're stored in DB) to users'timezone
(which you would store with in every user's settings) when you display the dates.
For the other people that also still have the wrong date/time after changing the config file:
My problem was in php in my vagrant box (Homestead).
To solve it I did:
First ssh into you vagrant box and then run this in the command line:
date
This should return something like "Mon Jul 3 13:48:52 CEST 2017". Check if this date/time is correct. If not do the following:
sudo ntpdate -b pool.ntp.org
This should update your system time. Check it again with the first command. If it is still not write you probably have to change your systems timezone. You can do this by running:
sudo rm -f /etc/localtime
sudo ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
You can use any timezone you wish, I prefer "Europe/Amsterdam".
You can get other timezones here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With