Changeset 14487 for trunk/wp-includes/formatting.php
- Timestamp:
- 05/06/2010 08:40:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r14428 r14487 1554 1554 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the 1555 1555 * value of the 'gmt_offset' option. Return format can be overridden using the 1556 * $format parameter 1556 * $format parameter. If PHP5 is supported, the function uses the DateTime and 1557 * DateTimeZone objects to respect time zone differences in DST. 1557 1558 * 1558 1559 * @since 1.2.0 … … 1565 1566 function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { 1566 1567 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); 1567 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1568 $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600); 1568 $tz = get_option('timezone_string'); 1569 if( class_exists('DateTime') && $tz ) { 1570 //PHP5 1571 date_default_timezone_set( $tz ); 1572 $datetime = new DateTime( $string ); 1573 $datetime->setTimezone( new DateTimeZone('UTC') ); 1574 $offset = $datetime->getOffset(); 1575 $datetime->modify( '+' . $offset / 3600 . ' hours'); 1576 $string_gmt = gmdate($format, $datetime->format('U')); 1577 1578 date_default_timezone_set('UTC'); 1579 } 1580 else { 1581 //PHP4 1582 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1583 $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600); 1584 } 1569 1585 return $string_gmt; 1570 1586 }
Note: See TracChangeset
for help on using the changeset viewer.