date_default_timezone_set function not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

date_default_timezone_set function not working

Post by oboedrew »

I am attempting to use the date_default_timezone_set function to override my web host's default timezone setting so that when I use the date function it returns a date that is correct for a specified timezone. However, this function is not working. I ran these two tests:

Code: Select all

 
Test One
 
date_default_timezone_set(America/New_York);
$timezone=date_default_timezone_get();
$date=date('Y-m-d H:i:');
echo
    "$timezone $date"
;
 

Code: Select all

 
Test Two
 
date_default_timezone_set(America/Los_Angeles);
$timezone=date_default_timezone_get();
$date=date('Y-m-d H:i:');
echo
    "$timezone $date"
;
 
In both tests, the output is the same: EST5EDT 2009-03-13 11:35.
EST5EDT is the default timezone set by my web host. The PHP version is 5.2.6.

Can anyone explain to me why date_default_timezone_set() is not working?

Thanks,
Drew
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: date_default_timezone_set function not working

Post by requinix »

Is that code copy/pasted from your script?

The city is supposed to be a string. You gave it two constants, one divided by the other.
The fact that you didn't see the two E_WARNINGs doesn't mean the code is correct.

Code: Select all

date_default_timezone_set("America/Los_Angeles");
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: date_default_timezone_set function not working

Post by oboedrew »

Oops! That fixed it.

Thanks,
Drew
Post Reply