I am wondering if we can also use the init_set()
function to set the default time.
init_set('date.timezone', 'Europe/Edinburgh');
The reason that I asked it was one other questions that I come across in a book. And the answer is only A.
Is the book wrong?
It should be A and C right? Thanks
There is also option D: use date_default_timezone_set
. The function you refer to in C is actually ini_set
. So the three ways are:
add a line in php.ini:
date.timezone = "Europe/Edinburgh"
use ini_set:
ini_set('date.timezone', 'Europe/Edinburgh');
use date_default_timezone_set:
date_default_timezone_set('Europe/Edinburgh');
The thing to note about options 2&3 is that they have to be called every time you run a script. So if you need to change the timezone for every script you run, it is easier to use option 1 (assuming you have edit access to php.ini).
As for option B, I guess in theory it could work but do you really want to play with your system's time? (hint: no).