WordPress RSS提要获取日期为UTC时间


WordPress RSS feeds get date is UTC time

我正在Wordpress中开发一个小部件,通过RSS提要导入体育比分。RSS提要项目有一个匹配日期和时间,所以它是非常重要的信息。RSS提要中的项目如下所示:[Sat,14 Nov 2015 15:00:00+0100],但当我想在变量中获取此日期时:

$date = $item->get_date();

我得到以下输出:2015年11月14日下午2:00

正确的时间应该是15:00(当地时间)。有人知道我如何从RSS源中获得正确的时间吗?

$rss = fetch_feed('http://www.volleybal.nl/application/handlers/export.php?format=rss&type=vereniging&programma=7141&iRegionId=7000');
if (!is_wp_error($rss)) : // Checks that the object is created correctly
    // Figure out how many total items there are, but limit it to 5. 
    $maxitems = $rss->get_item_quantity();
    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items(0, $maxitems);
endif;
foreach ($rss_items as $item) :
     $splitby = array('Wedstrijd:', 'Datum:', 'Speellocatie:');
     $text = esc_html($item->get_description());
     $split = explode(' ', $text);
     $result = array();
     $temp = array();
     $date = strtotime($item->get_date());
     $day = date('j M', $date);
     $time = date('G:i', $date);
 endforeach;

我在以下位置找到了解决方案:https://geek.hellyer.kiwi/2012/08/04/convert-utc-to-local-time-in-wordpress/

/*
* Converts UTC time to local time as set in WordPress
* Processes data in the format "Y-m-d H:i:s" (same format as used in WordPress core)
*
* @author Ryan Hellyer <ryanhellyer@gmail.com>
*/
function convert_time( $time ) {
$timestamp = strtotime( $time ); // Converting time to Unix timestamp
$offset = get_option( 'gmt_offset' ) * 60 * 60; // Time offset in seconds
$local_timestamp = $timestamp + $offset;
$local_time = date_i18n( 'Y-m-d H:i:s', $local_timestamp );
return $local_time;
}
$time = '2012-08-03 12:33:07';
echo convert_time( $time );