wc_rest_prepare_date_response()
Parses and formats a date for ISO8601/RFC3339.
Required WP 4.4 or later. See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
No Hooks.
Return
String|null
. ISO8601/RFC3339 formatted datetime.
Usage
wc_rest_prepare_date_response( $date, $utc );
- $date(string|null|WC_DateTime) (required)
- Date.
- $utc(true|false)
- Send false to get local/offset time.
Default: true
Changelog
Since 2.6.0 | Introduced. |
wc_rest_prepare_date_response() wc rest prepare date response code WC 7.7.0
function wc_rest_prepare_date_response( $date, $utc = true ) { if ( is_numeric( $date ) ) { $date = new WC_DateTime( "@$date", new DateTimeZone( 'UTC' ) ); $date->setTimezone( new DateTimeZone( wc_timezone_string() ) ); } elseif ( is_string( $date ) ) { $date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) ); $date->setTimezone( new DateTimeZone( wc_timezone_string() ) ); } if ( ! is_a( $date, 'WC_DateTime' ) ) { return null; } // Get timestamp before changing timezone to UTC. return gmdate( 'Y-m-d\TH:i:s', $utc ? $date->getTimestamp() : $date->getOffsetTimestamp() ); }