WordPress.org

Make WordPress Core

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#23384 closed defect (bug) (invalid)

Timezone Overwritten in wp-settings.php

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

Description

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)

comment:1 iandunn15 months 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 15 months ago by iandunn (previous) (diff)

comment:2 sterfry6815 months 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):http://wordpress.org/support/topic/timezone-overwritten-in-core?replies=7#post-3813653

comment:3 iandunn15 months 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.

comment:4 iandunn15 months ago

  • Component changed from General to Date/Time

comment:5 helen15 months ago

  • Milestone Awaiting Review deleted

comment:6 rmccue15 months 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.