iso8601_timezone_to_offset

Computes an offset in seconds from an iso8601 timezone.

Description

(int|float) iso8601_timezone_to_offset( (string) $timezone ); 

Returns (int|float)

The offset in seconds.

Parameters (1)

0. $timezone (string)
Either Z for 0 offset or hhmm..

Usage

  1. if ( !function_exists( 'iso8601_timezone_to_offset' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Either 'Z' for 0 offset or 'hhmm'. 
  5. $timezone = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = iso8601_timezone_to_offset($timezone); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function iso8601_timezone_to_offset( $timezone ) { 
  2. // $timezone is either 'Z' or '[+|-]hhmm' 
  3. if ($timezone == 'Z') { 
  4. $offset = 0; 
  5. } else { 
  6. $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; 
  7. $hours = intval(substr($timezone, 1, 2)); 
  8. $minutes = intval(substr($timezone, 3, 4)) / 60; 
  9. $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes); 
  10. return $offset;