WordPress at a glance

get_date_from_gmt() WP 1.0

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

Requires and returns a date in the Y-m-d H:i:s format. Return format can be overridden using the $format parameter.

Works based on: get_option()
✈ 1 time = 0.000149s = fast | 50000 times = 3.75s = fast

No Hooks.

Return

String. Formatted date relative to the timezone.

Usage

get_date_from_gmt( $string, $format );
$string(string) (required)
The date to be converted.
$format(string)
The format string for the returned date.
Default: 'Y-m-d H:i:s'

Changelog

Since 1.2.0 Introduced.

Code of get date from gmt: wp-includes/formatting.php WP 5.3.2

<?php
function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) {
	$datetime = date_create( $string, new DateTimeZone( 'UTC' ) );

	if ( false === $datetime ) {
		return gmdate( $format, 0 );
	}

	return $datetime->setTimezone( wp_timezone() )->format( $format );
}

Related Functions

From tag: date time

No comments
        Log In . Register