Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#23384 closed defect (bug) (invalid)

Timezone Overwritten in wp-settings.php

Reported by: sterfry68's profile sterfry68 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.1
Component: Date/Time Keywords:
Focuses: Cc:


wp-settings.php, line 36:

date_default_timezone_set( 'UTC' );

appears to be overriding the timezone selected in the dashboard and held in the options table. This code:

<?php echo date_default_timezone_get(); ?>

always returns UTC no matter what is in the options table. And when I comment out line 36 in wp-settings, I get the correct timezone. This problem has been verified by another user on the support forum.

I have employed a temporary fix by manually setting the timezone back to my option before calling a date function or class.

Change History (6)

#1 @iandunn
11 years ago

  • Cc ian_dunn@… added

In order to simplify timezone issues, WordPress always keeps track of time internally using UTC. Then, when the time is displayed it's converted the the local time that's defined in the Timezone setting on the General Settings page.

If you're getting a UTC time back from PHP's date() function, that's expected. You should be using WordPress' current_time() instead.

If that's not the problem, can you give a detailed description of the symptoms you're seeing? A link to the forum post you alluded to would also be helpful.

Last edited 11 years ago by iandunn (previous) (diff)

#2 @sterfry68
11 years ago

Interesting. So does this mean that I shouldn't use php's date() function or DateTime object?

Here's a link to the forum (probably won't help you much):

#3 @iandunn
11 years ago

  • Resolution set to invalid
  • Status changed from new to closed

That's right, as far as PHP is concerned, everything is UTC. It gets converted to your local timezone at the WordPress layer, so make sure you always use current_time() instead of date() or any other native PHP function. See the Codex entry for current_time() for more details.

#4 @iandunn
11 years ago

  • Component changed from General to Date/Time

#5 @helen
11 years ago

  • Milestone Awaiting Review deleted

#6 @rmccue
11 years ago

FWIW, if you really want to use DateTime, you can pass in a DateTimeZone object and use get_option('timezone_string') to get the local timezone for that.

Note: See TracTickets for help on using tickets.