rest_parse_date() - WordPress 函数参考中文文档

返回介绍

rest_parse_date()

发布于 2017-09-11 字数1533 浏览 856 评论 0

rest_parse_date( string $date,  bool $force_utc = false )

Parses an RFC3339 time into a Unix timestamp.


描述


参数

$date

(string)
(Required)
RFC3339 timestamp.

$force_utc

(bool)
(Optional)
Whether to force UTC timezone instead of using the timestamp’s timezone.

Default value: false


返回值

(int) Unix timestamp.


源代码

File: wp-includes/rest-api.php

function rest_parse_date( $date, $force_utc = false ) {
	if ( $force_utc ) {
		$date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date );
	}

	$regex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#';

	if ( ! preg_match( $regex, $date, $matches ) ) {
		return false;
	}

	return strtotime( $date );
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

Used By

  • wp-includes/rest-api.php:
    rest_validate_value_from_schema()
  • wp-includes/rest-api.php:
    rest_get_date_with_gmt()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!