wc_string_to_timestamp()WC 3.0.0

Convert mysql datetime to PHP timestamp, forcing UTC. Wrapper for strtotime.

Based on wcs_strtotime_dark_knight() from WC Subscriptions by Prospress.

Хуков нет.

Возвращает

int.

Использование

wc_string_to_timestamp( $time_string, $from_timestamp );
$time_string(строка) (обязательный)
Time string.
$from_timestamp(int|null)
Timestamp to convert from.
По умолчанию: null

Список изменений

С версии 3.0.0 Введена.

Код wc_string_to_timestamp() WC 8.7.0

function wc_string_to_timestamp( $time_string, $from_timestamp = null ) {
	$time_string = $time_string ?? '';

	$original_timezone = date_default_timezone_get();

	// @codingStandardsIgnoreStart
	date_default_timezone_set( 'UTC' );

	if ( null === $from_timestamp ) {
		$next_timestamp = strtotime( $time_string );
	} else {
		$next_timestamp = strtotime( $time_string, $from_timestamp );
	}

	date_default_timezone_set( $original_timezone );
	// @codingStandardsIgnoreEnd

	return $next_timestamp;
}