iso8601_timezone_to_offset()
iso8601_timezone_to_offset( string $timezone )
从iso8601时区计算以秒为单位的偏移量。
Computes an offset in seconds from an iso8601 timezone.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$timezone | (string) | 必需 | “Z”表示0偏移或“±hhmm”。 |
返回(Return)
(int|float)以秒为单位的偏移量。
源码(Source)
/** * Computes an offset in seconds from an iso8601 timezone. * * @since 1.5.0 * * @param string $timezone Either 'Z' for 0 offset or '±hhmm'. * @return int|float The offset in seconds. */ function iso8601_timezone_to_offset( $timezone ) { // $timezone is either 'Z' or '[+|-]hhmm' if ($timezone == 'Z') { $offset = 0; } else { $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; $hours = intval(substr($timezone, 1, 2)); $minutes = intval(substr($timezone, 3, 4)) / 60; $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes); } return $offset; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/formatting.php:3553 | 0 | 0 |
iso8601_timezone_to_offset() 为WP2原创文章,链接:https://www.wp2.cn/functions/iso8601_timezone_to_offset/