Change the timezone for a script

All your question about php
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Change the timezone for a script

Post by mister_v »

Hello,

I need to change the timezone to use the correct time with the function date()

Anyone known how to do this?
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Change the timezone for a script

Post by chris »

You can use the date_default_timezone_set() function

Code: Select all

date_default_timezone_set('America/Los_Angeles');
print date("Y-m-d");
date_default_timezone_set('Europe/Brussels');
print date("Y-m-d");
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Change the timezone for a script

Post by chris »

If you want to set it for all the scripts,
you can set it in php.ini

Code: Select all

[Date]
date.timezone = Your/Timezone
Post Reply