So I'm developing a php application locally and its getting the time wrong - it says its 20:45 when its 14:45 but mysql (also running locally) is getting it right. I've never noticed this before and I'm sure I've developed other applications locally that use the time.
Announcement
Collapse
No announcement yet.
Where does PHP get the time from?
Collapse
X
-
Tags: None
-
Php gets the time from the operating system but it applies any php time zone setting. mysql does the same, but applies the mysql time zone setting.
The php time zone setting can be set through -
date_default_timezone_set() function
date.timezone php.ini setting
TZ environment variable
Edit: Just found this in the manual -
Date/time support
Date/time support has been fully rewritten in PHP 5.1.x, and no longer uses the system settings to 'know' the timezone in operation. It will instead utilize, in the following order:
The timezone set using the date_default_timezone_set() function (if any)
The TZ environment variable (if non empty)
"magical" guess (if the operating system supports it)
If none of the above options succeeds, UTCFinding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.
-
huh, weird. My Default timezone is set to Asia/Jakarta. How strange, and annoying
Comment
-
... and
Originally posted by http://php.net/dateErrors/Exceptions
Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT message if using the system settings or the TZ environment variable. See also date_default_timezone_set()Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco
Comment
-
One of the higher priority settings is overriding it or the php version does not support it. That list does not mention it, but if you are on Windows, a registry setting can also set the value.
Edit: What does a phpinfo() statement show for the actual setting?Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.
Comment
-
There was no entry in php.ini for date.timezone (there is now) and phpinfo() listed date.timezone as 'no value' and default timezone to Asia/Jakarta. Changing the date.timezone ini value to Europe/London has them all showing Europe/London
Comment
Comment