返回介绍

rest_get_date_with_gmt()

发布于 2017-09-11 10:11:17 字数 2521 浏览 1007 评论 0 收藏 0

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

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


description


参数

$date

(string) (Required) RFC3339 timestamp.

$is_utc

(bool) (Optional) Whether the provided date should be interpreted as UTC.

Default value: false


返回值

(array|null) Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s), null on failure.


源代码

File: wp-includes/rest-api.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 );
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/rest-api.php: rest_parse_date()
  • wp-includes/formatting.php: get_gmt_from_date()
  • wp-includes/formatting.php: get_date_from_gmt()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::prepare_item_for_database()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文