timestamp_to_iso8601

Convert unix timestamp to ISO 8601 compliant date string.

Description

timestamp_to_iso8601( (int) $timestamp, (constant) $utc = true ); 

Parameters (2)

0. $timestamp (int)
Unix time stamp
1. $utc — Optional. (constant) => true
Whether the time stamp is UTC or local

Usage

  1. if ( !function_exists( 'timestamp_to_iso8601' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-globalpay/lib/class.nusoap_base.php'; 
  3.  
  4. // Unix time stamp 
  5. $timestamp = -1; 
  6.  
  7. // Whether the time stamp is UTC or local 
  8. $utc = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = timestamp_to_iso8601($timestamp, $utc); 
  12.  

Defined (2)

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

/lib/class.nusoap_base.php  
  1. function timestamp_to_iso8601($timestamp, $utc=true) { 
  2. $datestr = date('Y-m-d\TH:i:sO', $timestamp); 
  3. $pos = strrpos($datestr, "+"); 
  4. if ($pos === FALSE) { 
  5. $pos = strrpos($datestr, "-"); 
  6. if ($pos !== FALSE) { 
  7. if (strlen($datestr) == $pos + 5) { 
  8. $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); 
  9. if($utc) { 
  10. $pattern = '/'. 
  11. '([0-9]{4})-'. // centuries & years CCYY- 
  12. '([0-9]{2})-'. // months MM- 
  13. '([0-9]{2})'. // days DD 
  14. 'T'. // separator T 
  15. '([0-9]{2}):'. // hours hh: 
  16. '([0-9]{2}):'. // minutes mm: 
  17. '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... 
  18. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's 
  19. '/'; 
  20.  
  21. if(preg_match($pattern, $datestr, $regs)) { 
  22. return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]); 
  23. return false; 
  24. } else { 
  25. return $datestr; 
/lib/nusoap.php  
  1. function timestamp_to_iso8601($timestamp, $utc=true) { 
  2. $datestr = date('Y-m-d\TH:i:sO', $timestamp); 
  3. $pos = strrpos($datestr, "+"); 
  4. if ($pos === FALSE) { 
  5. $pos = strrpos($datestr, "-"); 
  6. if ($pos !== FALSE) { 
  7. if (strlen($datestr) == $pos + 5) { 
  8. $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); 
  9. if($utc) { 
  10. $pattern = '/'. 
  11. '([0-9]{4})-'. // centuries & years CCYY- 
  12. '([0-9]{2})-'. // months MM- 
  13. '([0-9]{2})'. // days DD 
  14. 'T'. // separator T 
  15. '([0-9]{2}):'. // hours hh: 
  16. '([0-9]{2}):'. // minutes mm: 
  17. '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... 
  18. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's 
  19. '/'; 
  20.  
  21. if(preg_match($pattern, $datestr, $regs)) { 
  22. return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]); 
  23. return false; 
  24. } else { 
  25. return $datestr;