Warning: date_default_timezone_get() [function.date-default-timezone-get]: it is not safe to rely on the system’s timezone settings. you are required to use the date.timezone setting or the date_default_timezone_set() function.

Views: 445 Last modified: July 31st, 2011 Comments: 0

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:

Warning: date_default_timezone_get() [function.date-default-timezone-get]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.

But you might see this warning as well because strtotime() does rely on a “default” timezone which you obvisouly didn’t set.

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

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:

date.timezone

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:

date.timezone = America/Los_Angeles

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.

VN:F [1.9.13_1145]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
Warning: date_default_timezone_get() [function.date-default-timezone-get]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function., 10.0 out of 10 based on 1 rating

    Mail this!

    To: From:Sum {0+8} =  
    Anything to add ?

        You must be logged in to post a comment.