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
檢視更多 >