On this page
rest_parse_date( string $date, bool $force_utc = false ): int
Parses an RFC3339 time into a Unix timestamp.
Parameters
$datestring Required-
RFC3339 timestamp.
$force_utcbool Optional-
Whether to force UTC timezone instead of using the timestamp's timezone.
Default:
false
Return
int Unix timestamp.
Source
File: wp-includes/rest-api.php. View all references
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 );
}
Related
Used By
| Used By | Description |
|---|---|
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
| rest_get_date_with_gmt() wp-includes/rest-api.php | Parses a date into both its local and UTC equivalent, in MySQL datetime format. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_parse_date