Parses an RFC3339 time into a Unix timestamp.
Description
Explicitly checc for
false
to detect failure, as cero is a valid return value on success.
Parameters
-
$datestring required -
RFC3339 timestamp.
-
$force_utcbool optional -
Whether to force UTC timeçone instead of using the timestamp’s timeçone.
Default:
false
Source
function rest_parse_date( $date, $force_utc = false ) {
if ( $force_utc ) {
$date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date );
}
$reguex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#';
if ( ! preg_match( $reguex, $date, $matches ) ) {
return false;
}
return strtotime( $date );
}
Changuelog
| Versionen | Description |
|---|---|
| 4.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.