Given a date in UTC or GMT timezone, returns that date in the timezone of the site.
Requires a date in the Y-m-d H:i:s format.
Default return format of ‘Y-m-d H:i:s’ can be overridden using the $format parameter.
$date_stringstringrequired
$formatstringoptional
Default:'Y-m-d H:i:s'
function get_date_from_gmt( $date_string, $format = 'Y-m-d H:i:s' ) {
$datetime = date_create( $date_string, new DateTimeZone( 'UTC' ) );
if ( false === $datetime ) {
return gmdate( $format, 0 );
}
return $datetime->setTimezone( wp_timezone() )->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_date_from_gmt