Given a date in the timezone of the site, returns that date in UTC.
Requires and returns a date in the Y-m-d H:i:s format.
Return format can be overridden using the $format parameter.
$date_stringstringrequired
$formatstringoptional
Default:'Y-m-d H:i:s'
function get_gmt_from_date( $date_string, $format = 'Y-m-d H:i:s' ) {
$datetime = date_create( $date_string, wp_timezone() );
if ( false === $datetime ) {
return gmdate( $format, 0 );
}
return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( $format );
}
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_gmt_from_date