Ticket #20398: 20398.diff
File 20398.diff, 1.7 KB (added by , 13 years ago) |
---|
-
formatting.
old new 1669 1669 /** 1670 1670 * Converts a GMT date into the correct format for the blog. 1671 1671 * 1672 * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of 1673 * gmt_offset.Return format can be overridden using the $format parameter 1672 * Requires and returns a date in the Y-m-d H:i:s format. Simply adds the value 1673 * of the 'gmt_offset' option. Return format can be overridden using the $format 1674 * parameter. The DateTime and DateTimeZone classes are used to respect time 1675 * zone differences in DST. 1674 1676 * 1675 1677 * @since 1.2.0 1676 1678 * … … 1679 1681 * @return string Formatted date relative to the GMT offset. 1680 1682 */ 1681 1683 function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') { 1682 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); 1683 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1684 $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600); 1684 $tz = get_option('timezone_string'); 1685 if ( $tz ) { 1686 date_default_timezone_set('UTC'); 1687 $datetime = new DateTime( $string ); 1688 $datetime->setTimezone( new DateTimeZone($tz) ); 1689 $string_localtime = $datetime->format($format); 1690 } else { 1691 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); 1692 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1693 $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600); 1694 } 1685 1695 return $string_localtime; 1686 1696 } 1687 1697