get_gmt_from_date [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Returns a date in the GMT equivalent.
Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the value of the 'gmt_offset' option. Return format can be overridden using the $format parameter. The DateTime and DateTimeZone classes are used to respect time zone differences in DST.
Source
<?php
function get_gmt_from_date($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);
$tz = get_option('timezone_string');
if ( $tz ) {
date_default_timezone_set( $tz );
$datetime = new DateTime( $string );
$datetime->setTimezone( new DateTimeZone('UTC') );
$offset = $datetime->getOffset();
$datetime->modify( '+' . $offset / 3600 . ' hours');
$string_gmt = gmdate($format, $datetime->format('U'));
date_default_timezone_set('UTC');
} else {
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
$string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
}
return $string_gmt;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/get gmt from date « WordPress Codex
Description. Returns a date in the GMT equivalent. Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the value of the 'gmt_offset' option.
codex.wordpress.org - WordPress › Support » Bug in get_gmt_from_date()?
Looking a bit at the WP code it appears that 'get_gmt_from_date()' uses the current 'gmt_offset' setting for all dates, even for dates in the "other" half of the year.
wordpress.org - get_gmt_from_date() WordPress function reference, arguments and ...
get_gmt_from_date(). Returns a date in the GMT equivalent. Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the value of the ' gmt_offset' ...
queryposts.com - get_gmt_from_date | A HitchHackers guide through WordPress
Feb 12, 2011 ... function get_gmt_from_date($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 ...
hitchhackerguide.com