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
查看更多 >