WordPress at Your Fingertips
function is not described

WC_API_Server::parse_datetime() public WC 2.1

Parse an RFC3339 datetime into a MySQl datetime

Invalid dates default to unix epoch

{} It's a method of the class: WC_API_Server{}

No Hooks.

Return

String. MySQl datetime (YYYY-MM-DD HH:MM:SS)

Usage

$WC_API_Server = new WC_API_Server();
$WC_API_Server->parse_datetime( $datetime );
$datetime(string) (required)
RFC3339 datetime

Changelog

Since 2.1 Introduced.

Code of WC_API_Server::parse_datetime() WC 5.7.1

public function parse_datetime( $datetime ) {

	// Strip millisecond precision (a full stop followed by one or more digits)
	if ( strpos( $datetime, '.' ) !== false ) {
		$datetime = preg_replace( '/\.\d+/', '', $datetime );
	}

	// default timezone to UTC
	$datetime = preg_replace( '/[+-]\d+:+\d+$/', '+00:00', $datetime );

	try {

		$datetime = new DateTime( $datetime, new DateTimeZone( 'UTC' ) );

	} catch ( Exception $e ) {

		$datetime = new DateTime( '@0' );

	}

	return $datetime->format( 'Y-m-d H:i:s' );
}