user3159364
user3159364

Reputation: 1

website displaying wrong timezone

I been breaking my brain about this one…

Ok so I set Ubuntu's time to my current time and changed the time zone to HST which is the one Im at and restarted cron.

I set the php.ini timezone to Pacific/Honolulu and set Wordpress Settings/Timezone to Pacific/Honolulu

Restarted nginx and php...

However when I

<?php echo date('e'); ?>

it displays UTC

am I missing anything? help!

Upvotes: 0

Views: 1255

Answers (5)

maryisdead
maryisdead

Reputation: 1810

Better late than never, so I'll chime in here. It's actually WordPress and the weird decision to set the default timezone back to UTC no matter what your INI settings might be. This delightful gem can be found in wp-settings.php (link is for trunk version, marked line might be off in the future).

I guess they did it to keep their internal time calculations easy and on a common base. I do understand the intention behind this but still think it's awkward and surely has caused lots of confusion and trouble for users and developers (like me just now). They could've kept it internal.

Anyways, the bottom line is: When doing your own time calculations in a theme or plug-in or whatever, be sure to explicitly set the timezone beforehand.

Just using time() and thinking you're good to go might lead to headaches. You can get what is set in the settings panel via get_option('timezone_string') and for example use that in conjunction with date_default_timezone_set.

Weston Ruter summed this all up just fine and also suggests using PHP's date and time related classes and explicitly setting the timezone for them.

Upvotes: 0

ajtrichards
ajtrichards

Reputation: 30565

In your php.ini file make sure you set:

date.timezone = "America/Los_Angeles"

And then change your server time to the appropriate timezone using:

sudo dpkg-reconfigure tzdata

Upvotes: 0

cnst
cnst

Reputation: 27238

What was your system timezone set to when you've originally started nginx?

Did you actually shutdown nginx, and then started it up from scratch, or did you simply made it re-read its configuration file? (FYI: the popular cat /var/run/nginx.pid | xargs kill -HUP would not result in a restart.)

Your best bet would probably be to do something like sudo sh -c "cat /usr/share/zoneinfo/Pacific/Honolulu > /etc/localtime", remove any timezone mentions from the individual apps, and then properly shutdown and startup the whole server.

Upvotes: 0

ZombieBunnies
ZombieBunnies

Reputation: 268

Set the timzone within the script.

date_default_timezone_set('PST');
date('e');

Upvotes: 0

Premjith
Premjith

Reputation: 19

Try following,

<?php
date_default_timezone_set('America/Los_Angeles');
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
?>

Upvotes: 1

Related Questions