WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#11672 closed defect (bug) (fixed)

current_time() does not correctly retrun localized time

Reported by: hiromasa Owned by: nbachiyski
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9
Component: Date/Time Keywords:
Focuses: Cc:

Description

When you set you set timezone using a city name, current_time() function in functions.php does not return correct local time.

Cause:

When you get gmt_offset(), the wp_timezone_override_offset() hook offsets the timezone again after date_default_timezone_set sets the timezone (this happens only when timezone_string exists).

Example 1:

Your timezone is set to "Tokyo" (UTC+9), using the city name. wp_options will contain:

timezone_string	Asia/Tokyo
gmt_offset      ''

Code below will incorrectly retun UTC+9+9.

<?php echo date('Y-m-d H:i:s', current_time( 'timestamp' )); ?>

Example 2:

Your timezone is set to "UTC+9" (WordPress 2.9.1 RC1). wp_options will contain:

timezone_string	''
gmt_offset      9

Code below will correctly retun UTC+9.

<?php echo date('Y-m-d H:i:s', current_time( 'timestamp' )); ?>

Change History (4)

comment:2 @ryan6 years ago

  • Component changed from General to Date/Time

comment:3 @ryan6 years ago

  • Milestone changed from Unassigned to 3.0

comment:4 @ryan5 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.