iso8601_timezone_to_offset

函式
iso8601_timezone_to_offset ( $timezone )
引數
  • (string) $timezone Either 'Z' for 0 offset or '±hhmm'.
    Required:
返回值
  • (int|float) The offset in seconds.
定義位置
相關方法
wp_timezone_override_offsetwp_timezone_choicewp_timezone_stringiso8601_to_datetimewp_timezone_supported
引入
1.5.0
棄用
-

iso8601_timezone_to_offset: 這是WordPress中的一個函式,將ISO8601時區字串轉換為UTC偏移量。它可以用來將一個時區字串轉換為與UTC偏移的小時數。

給定一個ISO 8601時區,返回其UTC偏移量,單位為秒。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function iso8601_timezone_to_offset( $timezone ) {
// $timezone is either 'Z' or '[+|-]hhmm'.
if ( 'Z' === $timezone ) {
$offset = 0;
} else {
$sign = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1;
$hours = (int) substr( $timezone, 1, 2 );
$minutes = (int) substr( $timezone, 3, 4 ) / 60;
$offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
}
return $offset;
}
function iso8601_timezone_to_offset( $timezone ) { // $timezone is either 'Z' or '[+|-]hhmm'. if ( 'Z' === $timezone ) { $offset = 0; } else { $sign = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1; $hours = (int) substr( $timezone, 1, 2 ); $minutes = (int) substr( $timezone, 3, 4 ) / 60; $offset = $sign * HOUR_IN_SECONDS * ( $hours + $minutes ); } return $offset; }
function iso8601_timezone_to_offset( $timezone ) {
	// $timezone is either 'Z' or '[+|-]hhmm'.
	if ( 'Z' === $timezone ) {
		$offset = 0;
	} else {
		$sign    = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1;
		$hours   = (int) substr( $timezone, 1, 2 );
		$minutes = (int) substr( $timezone, 3, 4 ) / 60;
		$offset  = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
	}
	return $offset;
}

常見問題

FAQs
檢視更多 >