dongqiao3927 2017-01-26 19:38
浏览 125
已采纳

用PHP更改日期

I have a PHP bookmarking script I'm using that builds an RSS feed from my bookmarks (script is Semantic Scuttle). Each item in the RSS looks like the below.

<item>
    <title>Technology and the Evolution of the Designer’s Role</title>
    <link>https://blogs.adobe.com/creativecloud/technology-and-the-evolution-of-the-designers-role</link>
    <guid>http://apps.timpaneeze.com/bookmarks/www/#7</guid>
    <description>Today, we often associate design with activities like user experience, graphic and web design, or perhaps fashion and product design. Mass communications and mass production brought with them the need for specific skills in creating posters and products. Each wave of technological change brings with it an evolution in the role and activities that designers undertake.</description>
    <dc:creator>bobroberts</dc:creator>
    <pubDate>Fri, 27 Jan 2017 00:05:50 +0000</pubDate>
    <category>design</category>
</item>

The pubdate doesn't match the time I actually create the bookmark in the system, and there's no UI to change it. I found online advice to use strtotime($row['bDatetime']) - 60 * 60 * 14 to change the time (one post was 14 hours off). That is not actually fixing the date, though. For some items the resulting time is correct, but not for others.

I also pull the RSS feed items into WordPress, where the time gets even screwier. WP brought that RSS item in with a future publish time of 26 Jan 2017, 18:05. That WP install is set to Los Angeles (Pacific) timezone.

So, quick recap:

  • I create the bookmark at 10:05 Pacific
  • The bookmarking system marks that creation time as 05:05 the same day
  • WP imports that as 18:05 the same day
  • Using strtotime($row['bDatetime']) - 60 * 60 * 5 doesn't reliably fix every pubDate

How do I make these match up?

Is the +0000 in the pubdate the key? If so, how do I modify that?

The only place the pubdate appears in the bookmarking script files is here. You can see the original line last and my unsuccessful attempt to fix it at the top:

$_pubdate = gmdate('r', strtotime($row['bDatetime']) - 60 * 60 * 14);
/* PSB EDIT Replaced below line with above. */
/*    $_pubdate = gmdate('r', strtotime($row['bDatetime']));  */
  • 写回答

1条回答 默认 最新

  • dr897777 2017-01-26 20:18
    关注

    After some time in the chat room, the question boiled down to converting a MySQL date string to an RFC822 date string, while maintaining the correct time zone. This is the code that ended up working:

    $timestamp = strtotime($row["bDatetime"]);
    if (date("I", $timestamp) == 1) {
        $offset = 25200;
    } else {
        $offset = 28800;
    }
    $_pubdate = date("r", $timestamp - $offset);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败