How to fix “date(): It is not safe to rely on the system’s timezone settings…” error with PHP?

Spread the love

Sometimes, we want to fix "date(): It is not safe to rely on the system’s timezone settings…" error with PHP.

In this article, we’ll look at how to fix "date(): It is not safe to rely on the system’s timezone settings…" error with PHP.

How to fix "date(): It is not safe to rely on the system’s timezone settings…" error with PHP?

To fix "date(): It is not safe to rely on the system’s timezone settings…" error with PHP, we can set the time zone with date_default_timezone_set.

For instance, we write

if (!ini_get("date.timezone")) {
    date_default_timezone_set("GMT");
}

to check if the time zone is set with ini_get.

If it’s not, then we set the time zone to GMT with date_default_timezone_set.

Conclusion

To fix "date(): It is not safe to rely on the system’s timezone settings…" error with PHP, we can set the time zone with date_default_timezone_set.

Leave a Reply

Your email address will not be published.