Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Default Timezone Config

Tags:

php

I noticed today that the date reported by PHP is wrong.

When I went into the PHP file to try to change the timezone, I get a big ugly warning saying it is mandatory to set the timezone.

I get no error when the timezone is set to UTC but the date is wrong.

Every other value besides UTC throws the error.

What is this?

like image 500
Johnny Mnemonic Avatar asked Aug 13 '12 01:08

Johnny Mnemonic


People also ask

How do I change the default timezone in PHP?

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

What is the default time zone?

US' Default Time Zone Unfortunately, there is no default time, so you have to change your time depending on the time zone used in the place.

Where does PHP get timezone from?

Definition and Usage. The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.


1 Answers

date.timezone = "Europe/Paris"

Put that in your php.ini file with the approrpriate timezone from here, and then restart your HTTP server.

If you don't want to set it globally, but want to set it on a script-by-script basis, use this code on each page where a date/time function is used:

date_default_timezone_set('America/Los_Angeles');

Like the global timezone setting, pick your timezone from here.

like image 175
David Avatar answered Oct 20 '22 10:10

David