Its quite obvious you will collide with this error once in your life (Huge chance it’s not related to date_default_timezone_get(), but another function).
So you might see this warning:
But you might see this warning as well because strtotime() does rely on a “default” timezone which you obvisouly didn’t set.
Those warnings can occur for all of the date/time functions relying on the default timezone.
Moreover, this warning will occur when you haven’t declared a default timezone yet, where your date/time functions can rely on while the script does it’s thing.
Declaring a timezone can be done on two ways. The first option would be changing the php.ini file so the timezone would be loaded each time a script runs. Open your php.ini file and search for the following directive:
If you find a semicolon in front of it, remove it. This directive will hold your default timezone. You can choose a timezone from the official PHP website.
We will use America/Los_Angeles as example. Fill in the value of the timezone as this:
Save your php.ini file and restart your server. From now on, your date/time functions will rely on this setting.
The second option to solve this warning is by using a already existing PHP build-in function “date_default_timezone_set()”. Somewhere before your date/time function type the following line as this:
<?php
// Set timezone
date_default_timezone_set('America/Los_Angeles');
// Create string, date of tomorrow
echo date('Y m-d', strtotime('+1 day', time()));
?>
This function will only work within the function it has been placed in, or the whole scope of the file when placed outside functions, nowhere else.
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments