Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#23384 closed defect (bug) (invalid)

Timezone Overwritten in wp-settings.php

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

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)

  • 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 symptom's you're seeing? A link to the forum post you alluded to would also be helpful.

Version 0, edited 4 months ago by iandunn (next)

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

  • 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.

  • Component changed from General to Date/Time
  • Milestone Awaiting Review deleted

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.