Advertisements

get_date_from_gmt

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

Converts a GMT date into the correct format for the blog.
Requires and returns in the Y-m-d H:i:s format. Simply adds the value of gmt_offset.Return format can be overridden using the $format parameter

Parameters

  • string $string: The date to be converted.
  • string $format: The format string for the returned date (default is Y-m-d H:i:s)

Return values

returns:Formatted date relative to the GMT offset.

Source code

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

	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);

	$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')*3600);

	return $string_localtime;

}

1350

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: