wp_timezone_string

函数
wp_timezone_string ( No parameters )
返回值
  • (string) PHP timezone name or a ±HH:MM offset.
定义位置
相关方法
wp_timezonewp_timezone_choicewp_timezone_supportedwp_installingimage_hwstring
引入
5.3.0
弃用
-

wp_timezone_string: 这个函数检索在常规设置中设置的WordPress时区字符串。

检索网站的时区为一个字符串。

如果有的话,使用`timezone_string`选项来获取一个合适的时区名称,否则就退回到手动UTC±偏移。

返回值的例子:
– ‘Europe/Rome’
– ‘America/North_Dakota/New_Salem’
– ‘UTC’
– ‘-06:30’
– ‘+00:00’
– ‘+08:45’

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;
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 19:32:59

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: