rest_parse_date

Parses an RFC3339 time into a Unix timestamp.

Description

(int) rest_parse_date( (string) $date, (bool) $force_utc = false ); 

Returns (int)

Unix timestamp.

Parameters (2)

0. $date (string)
RFC3339 timestamp.
1. $force_utc — Optional. (bool) => false
Whether to force UTC timezone instead of using the timestamp's timezone. Default false.

Usage

  1. if ( !function_exists( 'rest_parse_date' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4. // RFC3339 timestamp. 
  5. $date = ''; 
  6.  
  7. // Optional. Whether to force UTC timezone instead of using 
  8. // the timestamp's timezone. Default false. 
  9. $force_utc = false; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = rest_parse_date($date, $force_utc); 
  13.  

Defined (1)

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

/wp-includes/rest-api.php  
  1. function rest_parse_date( $date, $force_utc = false ) { 
  2. if ( $force_utc ) { 
  3. $date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date ); 
  4.  
  5. $regex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#'; 
  6.  
  7. if ( ! preg_match( $regex, $date, $matches ) ) { 
  8. return false; 
  9.  
  10. return strtotime( $date );