get_date_from_gmt( string $string, string $format = 'Y-m-d H:i:s' )

Converts a GMT date into the correct format for the blog.


Description Description

Requires and returns a date in the Y-m-d H:i:s format. If there is a timezone_string available, the returned date is in that timezone, otherwise it simply adds the value of gmt_offset. Return format can be overridden using the $format parameter


Parameters Parameters

$string

(string) (Required) The date to be converted.

$format

(string) (Optional) The format string for the returned date (default is Y-m-d H:i:s)

Default value: 'Y-m-d H:i:s'


Top ↑

Return Return

(string) Formatted date relative to the timezone / GMT offset.


Top ↑

Source Source

File: wp-includes/formatting.php

function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) {
	$tz = get_option( 'timezone_string' );
	if ( $tz ) {
		$datetime = date_create( $string, new DateTimeZone( 'UTC' ) );
		if ( ! $datetime )
			return date( $format, 0 );
		$datetime->setTimezone( new DateTimeZone( $tz ) );
		$string_localtime = $datetime->format( $format );
	} else {
		if ( ! preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches) )
			return date( $format, 0 );
		$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
		$string_localtime = gmdate( $format, $string_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
	}
	return $string_localtime;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.