以MySQL日期时间格式分析其本地和UTC等效日期。

原型

rest_get_date_with_gmt( string $date, bool $is_utc = false )

参数

$date (string) (Required) RFC3339时间戳。

$is_utc (bool) (Optional) 是否应将提供的日期解释为UTC。

返回值

(array|null)  本地和UTC日期时间字符串,采用MySQL日期时间格式(Y-m-d H:i:s),失败时为null。

源文件

路径: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 = date( 'Y-m-d H:i:s', $date );
		$utc = get_gmt_from_date( $local );
	} else {
		$utc = date( 'Y-m-d H:i:s', $date );
		$local = get_date_from_gmt( $utc );
	}
	return array( $local, $utc );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/rest_get_date_with_gmt/