WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

rest_get_date_with_gmt() WP 4.4.0

Parses a date into both its local and UTC equivalent, in MySQL datetime format.

Хуков нет.

Возвращает

Массив/null. Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s), null on failure.

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

rest_get_date_with_gmt( $date, $is_utc );
$date(строка) (обязательный)
RFC3339 timestamp.
$is_utc(true/false)
Whether the provided date should be interpreted as UTC.
По умолчанию: false

Заметки

  • Смотрите: rest_parse_date()

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

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

Код rest_get_date_with_gmt() WP 5.5.1

wp-includes/rest-api.php
<?php
function rest_get_date_with_gmt( $date, $is_utc = false ) {
	/*
	 * Whether or not the original date actually has a timezone string
	 * changes the way we need to do timezone conversion.
	 * Store this info before parsing the date, and use it later.
	 */
	$has_timezone = preg_match( '#(Z|[+-]\d{2}(:\d{2})?)$#', $date );

	$date = rest_parse_date( $date );

	if ( empty( $date ) ) {
		return null;
	}

	/*
	 * At this point $date could either be a local date (if we were passed
	 * a *local* date without a timezone offset) or a UTC date (otherwise).
	 * Timezone conversion needs to be handled differently between these two cases.
	 */
	if ( ! $is_utc && ! $has_timezone ) {
		$local = gmdate( 'Y-m-d H:i:s', $date );
		$utc   = get_gmt_from_date( $local );
	} else {
		$utc   = gmdate( 'Y-m-d H:i:s', $date );
		$local = get_date_from_gmt( $utc );
	}

	return array( $local, $utc );
}