WordPress开发者和主题制作者的搜索引擎



rest_parse_date ›

Since4.4.0
已弃用n/a
rest_parse_date ( $date, $force_utc = false )
参数: (2)
  • (string) $date RFC3339 timestamp.
    Required: Yes
  • (bool) $force_utc Optional. Whether to force UTC timezone instead of using the timestamp's timezone. Default false.
    Required: No
    默认: false
返回:
  • (int) Unix timestamp.
定义在:
文档:

Parses an RFC3339 time into a Unix timestamp.



源码

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 );
}