wp_timezone_string()
Gets the time zone from the site settings (as a string).
The data is taken as is from the option get_option( 'timezone_string' ). If this option is empty, the result will be assembled based on data from another option: get_option( 'gmt_offset' ).
Used By: wp_timezone()
1 time — 0.0030341 sec (very slow) | 50000 times — 1.60 sec (fast)
No Hooks.
Returns
String. The time zone or the time zone offset in the format: ±HH:MM.
Usage
wp_timezone_string();
Examples
#1 Demo
echo wp_timezone_string(); // Asia/Tashkent // when the timezone_string option is empty echo wp_timezone_string(); // +02:00
Changelog
| Since 5.3.0 | Introduced. |
wp_timezone_string() wp timezone string code WP 6.9
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;
}