iso8601_timezone_to_offset( string $timezone )

Given an ISO 8601 timezone, returns its UTC offset in seconds.


Parameters Parameters

$timezone

(string) (Required) Either 'Z' for 0 offset or '±hhmm'.


Top ↑

Return Return

(int|float) The offset in seconds.


Top ↑

More Information More Information

SeeĀ  Also: ISO 8601


Top ↑

Source Source

File: wp-includes/formatting.php

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   = intval( substr( $timezone, 1, 2 ) );
		$minutes = intval( substr( $timezone, 3, 4 ) ) / 60;
		$offset  = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
	}
	return $offset;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.