rest_parse_date

函数
rest_parse_date ( $date, $force_utc = false )
参数
  • (string) $date RFC3339 timestamp.
    Required:
  • (bool) $force_utc Optional. Whether to force UTC timezone instead of using the timestamp's timezone. Default false.
    Required:
    Default: false
返回值
  • (int) Unix timestamp.
定义位置
相关方法
rest_parse_hex_colorget_the_dateget_core_updateslist_core_updaterest_parse_request_arg
引入
4.4.0
弃用
-

rest_parse_date:这是一个WordPress的函数,它解析一个日期字符串并返回一个相应的Unix时间戳: 该函数接收一个日期字符串和一个格式参数,并返回相应的Unix时间戳: 这个函数用来解析传递给WordPress REST API的日期字符串。

将RFC3339时间解析为Unix时间戳。

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

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 15:32:55

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: