iso8601_timezone_to_offset() WordPress Function

The iso8601_timezone_to_offset() function converts a timezone string to a numeric offset. The function is useful for converting timestamps between timezones.

iso8601_timezone_to_offset( string $timezone ) #

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


Parameters

$timezone

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


Top ↑

Return

(int|float) The offset in seconds.


Top ↑

More Information

See  Also: ISO 8601


Top ↑

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

Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More