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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里