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

Parses an RFC3339 time into a Unix timestamp.


Parameters Parameters

$date

(string) (Required) RFC3339 timestamp.

$force_utc

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

Default value: false


Top ↑

Return Return

(int) Unix timestamp.



Top ↑

Source Source

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

Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.