1 | <?php |
---|
2 | function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { |
---|
3 | 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); |
---|
4 | $tz = get_option('timezone_string'); |
---|
5 | date_default_timezone_set( $tz ); |
---|
6 | $datetime = new DateTime( $string ); |
---|
7 | $datetime->setTimezone( new DateTimeZone('UTC') ); |
---|
8 | $offset = $datetime->getOffset(); |
---|
9 | $datetime->modify( '+' . $offset / 3600 . ' hours'); |
---|
10 | $string_gmt = gmdate($format, $datetime->format('U')); |
---|
11 | date_default_timezone_set('UTC'); |
---|
12 | return $string_gmt; |
---|
13 | } |
---|
14 | |
---|
15 | function get_option( $option ) |
---|
16 | { |
---|
17 | // Fudge get_option() outside of WP paradigm |
---|
18 | return 'America/Chicago'; |
---|
19 | } |
---|
20 | |
---|
21 | echo get_gmt_from_date('2001-03-01 12:34:56'); |
---|