Tribe__Date_Utils::wp_strtotime( string $string )
Converts a locally-formatted date to a unix timestamp. This is a drop-in replacement for strtotime(), except that where strtotime assumes GMT, this assumes local time (as described below). If a timezone is specified, this function defers to strtotime().
Contents
If there is a timezone_string available, the date is assumed to be in that timezone, otherwise it simply subtracts the value of the ‘gmt_offset’ option.
See also
Parameters
- $string
-
(string) (Required) A date/time string. See
strtotimefor valid formats
Return
(int) UNIX timestamp.
Source
File: src/Tribe/Date_Utils.php
public static function wp_strtotime( $string ) {
// If there's a timezone specified, we shouldn't convert it
try {
$test_date = new DateTime( $string );
if ( 'UTC' != $test_date->getTimezone()->getName() ) {
return strtotime( $string );
}
} catch ( Exception $e ) {
return strtotime( $string );
}
$tz = get_option( 'timezone_string' );
if ( ! empty( $tz ) ) {
$date = date_create( $string, new DateTimeZone( $tz ) );
if ( ! $date ) {
return strtotime( $string );
}
$date->setTimezone( new DateTimeZone( 'UTC' ) );
return $date->format( 'U' );
} else {
$offset = (float) get_option( 'gmt_offset' );
$seconds = intval( $offset * HOUR_IN_SECONDS );
$timestamp = strtotime( $string ) - $seconds;
return $timestamp;
}
}