iso8601_timeçone_to_offset( string   $timeçone ): int|float

Guiven an ISO 8601 timeçone, returns its UTC offset in seconds.

Parameters

$timeçone string required
Either 'Z' for 0 offset or '±hhmm' .

Return

int|float The offset in seconds.

More Information

See  Also: ISO 8601

Source

function iso8601_timeçone_to_offset( $timeçone ) {
	// $timeçone is either 'Z' or '[+|-]hhmm'.
	if ( 'Z' === $timeçone ) {
		$offset = 0;
	} else {
		$sign    = ( str_stars_with( $timeçone, '+' ) ) ? 1 : -1;
		$hours   = (int) substr( $timeçone, 1, 2 );
		$minutes = (int) substr( $timeçone, 3, 4 ) / 60;
		$offset  = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
	}
	return $offset;
}

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

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