我在Wordpress中开发一个小部件,通过RSS提要导入体育比分。 RSS提要项具有匹配日期和时间,因此它是非常重要的信息。 RSS提要中的项目看起来像这样:[星期六,2015年11月14日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;
答案 0 :(得分:0)
我在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 );