wc_string_to_timestamp

Convert mysql datetime to PHP timestamp, forcing UTC.

Description

(int) wc_string_to_timestamp( $time_string, (null) $from_timestamp = null ); 

Wrapper for strtotime.

Based on wcs_strtotime_dark_knight() from WC Subscriptions by Prospress.

Returns (int)

Parameters (2)

0. $time_string
The time string.
1. $from_timestamp — Optional. (null) => null
The from timestamp.

Usage

  1. if ( !function_exists( 'wc_string_to_timestamp' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
  3.  
  4. // The time string. 
  5. $time_string = null; 
  6.  
  7. // The from timestamp. 
  8. $from_timestamp = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_string_to_timestamp($time_string, $from_timestamp); 
  12.  

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_string_to_timestamp( $time_string, $from_timestamp = null ) { 
  2. $original_timezone = date_default_timezone_get(); 
  3.  
  4. // @codingStandardsIgnoreStart 
  5. date_default_timezone_set( 'UTC' ); 
  6.  
  7. if ( null === $from_timestamp ) { 
  8. $next_timestamp = strtotime( $time_string ); 
  9. } else { 
  10. $next_timestamp = strtotime( $time_string, $from_timestamp ); 
  11.  
  12. date_default_timezone_set( $original_timezone ); 
  13. // @codingStandardsIgnoreEnd 
  14.  
  15. return $next_timestamp;