douxin8749 2015-11-13 19:01
浏览 65
已采纳

WordPress RSS feed获取日期是UTC时间

I'm developing a widget in Wordpress to import sport scores through a RSS feed. The RSS feed items have a which is the match date and time, so it's really important information. The item in the RSS feed look likes this: [ Sat, 14 Nov 2015 15:00:00 +0100 ], but when I want to get this date in a variable with:

$date = $item->get_date();

I'm getting the following output: 14 November 2015, 2:00 pm

The right time should be 15:00 (local). Does anybody know how I can get the right time from the RSS feed?

$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;
  • 写回答

1条回答 默认 最新

  • duangai1941 2015-11-16 20:38
    关注

    I found a solution at: 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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀