【问题标题】:Convert int-date to RSS PubDate RFC 822 PHP将 int-date 转换为 RSS PubDate RFC 822 PHP
【发布时间】:2013-10-29 17:28:51
【问题描述】:

我有一个让我发疯的问题, 我的任务是从 API 解析日期并将其转换为 RFC 822 格式,因为出来的提要出现验证错误

API 中的日期如下所示:

<review created="2012-10-23 14:51:12.0">

我在 substr 的描述中有一个日期

$xtime = substr($review["created"], 0, 16);
$jahr = substr($xtime,0,4);
$mon  = substr($xtime,5,2);
$tag  = substr($xtime,8,2);
$datneu = $tag.'.'.$mon.'.'.$jahr; 

此日期将呈现为:

23.10.2012

对于我制作的发布日期

$xtime = substr($review["created"], 0, 16);
$xxl = $pubtime . " GMT";

渲染为:

2012-10-23 14:51:12 GMT

W3C 提要验证器说它没有验证,因为 pubDate 不是 RFC 822 形式

Sorry

This feed does not validate.

line 10, column 38: pubDate must be an RFC-822 date-time: 2012-10-29 11:51:23 GMT (5 occurrences) [help]

          <pubDate>2012-10-29 11:51:23 GMT</pubDate>

它需要看起来像:

<pubDate>Wed, 02 Oct 2002 13:00:00 GMT</pubDate>

我可以想象一个 hacky 解决方案来表达“if (month = 01){ actualmonth = Jan}”,但我真的不知道如何处理这些日子,

我也不太习惯 PHP,但我需要尽快解决这个问题。

希望你能帮助我,一定有我在类似问题中没有找到的解决方案

问候约翰

【问题讨论】:

    标签: php validation rss w3c pubdate


    【解决方案1】:

    看看DateTime::createFromFormat()date_create_from_format

    http://fr2.php.net/manual/en/datetime.createfromformat.php

    <?php
    $date = date_create_from_format('Y-m-d H:i:s', '2012-10-23 14:51:12.0');
    echo date_format($date, 'D, d M Y H:i:s');
    ?>
    

    查看可能的日期格式

    http://fr2.php.net/manual/en/function.date.php

    编辑:已修复

    【讨论】:

      【解决方案2】:

      你好,在 PHP 中你应该看看这个:function date

      【讨论】:

        【解决方案3】:

        对我来说工作,太棒了!

        对于其他人来说,我的案例的确切解决方案是


        $before = "2012-10-23 14:51:12.0";
        
        
        $timetwo = substr($before, 0, 16);
        
        $timethree = date_create_from_format('Y-m-d H:i:s', $timetwo);
        
        $timefinal = date_format(timethree, 'D, d M Y H:i:s');
        
        $after = $timefinal . ' GMT' ; 
        
        
        $after = "Mon, 23 Oct 2012 14:51:12 GMT";
        

        非常感谢您的快速回答,您太棒了!

        【讨论】:

          【解决方案4】:

          这对我有用....

          date("r", strtotime($yourdate))
          

          $yourdate 是 2013-10-27,我得到 Sun, 27 Oct 2013 00:00:00 +0000

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-06-04
            • 1970-01-01
            • 2020-07-18
            • 2020-07-08
            • 2020-06-29
            • 2015-12-12
            • 1970-01-01
            • 2010-09-22
            相关资源
            最近更新 更多