wp_timezone_string

The timeline below displays how wordpress function wp_timezone_string has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.9

/**
 * Retrieves the timezone of the site as a string.
 *
 * Uses the `timezone_string` option to get a proper timezone name if available,
 * otherwise falls back to a manual UTC ± offset.
 *
 * Example return values:
 *
 *  - 'Europe/Rome'
 *  - 'America/North_Dakota/New_Salem'
 *  - 'UTC'
 *  - '-06:30'
 *  - '+00:00'
 *  - '+08:45'
 *
 * @since 5.3.0
 *
 * @return string PHP timezone name or a ±HH:MM offset.
 */
function wp_timezone_string()
{
    $timezone_string = get_option('timezone_string');
    if ($timezone_string) {
        return $timezone_string;
    }
    $offset = (float) get_option('gmt_offset');
    $hours = (int) $offset;
    $minutes = $offset - $hours;
    $sign = ($offset < 0) ? '-' : '+';
    $abs_hour = abs($hours);
    $abs_mins = abs($minutes * 60);
    $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins);
    return $tz_offset;
}

WordPress Version: 5.3

/**
 * Retrieves the timezone from site settings as a string.
 *
 * Uses the `timezone_string` option to get a proper timezone if available,
 * otherwise falls back to an offset.
 *
 * @since 5.3.0
 *
 * @return string PHP timezone string or a ±HH:MM offset.
 */
function wp_timezone_string()
{
    $timezone_string = get_option('timezone_string');
    if ($timezone_string) {
        return $timezone_string;
    }
    $offset = (float) get_option('gmt_offset');
    $hours = (int) $offset;
    $minutes = $offset - $hours;
    $sign = ($offset < 0) ? '-' : '+';
    $abs_hour = abs($hours);
    $abs_mins = abs($minutes * 60);
    $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins);
    return $tz_offset;
}