簡體   English   中英

WordPress RSS源獲取日期為UTC時間

[英]WordPress RSS feeds get date is UTC time

我正在Wordpress中開發一個小部件,以通過RSS feed導入運動成績。 RSS提要項的日期和時間是匹配日期,因此這是非常重要的信息。 RSS feed中的項目看起來像這樣:[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 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM