2017-01-26 69 views
2

我有一个PHP书签脚本,我正在使用它从我的书签(脚本是Semantic Sc​​uttle)构建一个RSS订阅源。 RSS中的每个项目如下所示。在PHP中更改日期

<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> 

pubdate与我在系统中实际创建书签的时间不匹配,并且没有UI来更改它。我发现在线建议使用strtotime($row['bDatetime']) - 60 * 60 * 14来改变时间(一个职位是14小时关闭)。不过,这实际上并没有确定日期。对于某些项目,结果时间是正确的,但不适用于其他项目。

我也将RSS提要项目拉入WordPress,时间变得更加麻烦。 WP将该RSS项目带入未来发布时间为2017年1月26日18:05。 WP安装设置为洛杉矶(太平洋)时区。

所以,快速回顾一下:

  • 我在10:05创建书签太平洋
  • 的书签系统,标志着创建时间为05:05当天
  • WP进口,截至18: 05当天
  • 使用strtotime($row['bDatetime']) - 60 * 60 * 5不可靠的修复每一个pubdate的

如何让这些比赛呢?

pubdate中的+0000是关键吗?如果是这样,我该如何修改它?

这里只有pubdate出现在书签脚本文件中。你可以看到最后的原始行和我的不成功的尝试在顶部修复:

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

还试图(没有成功)将下面为php.ini ' php_value date.timezone “美国/洛杉矶” ' – iampariah

+0

另外没有效果将'SetEnv TZ America/Los_Angeles'添加到.htaccess中 – iampariah

回答

2

后在聊天室有一段时间,这个问题归结为一个MySQL日期字符串转换为RFC822日期字符串,而保持正确的时区。这是结束了工作的代码:

$timestamp = strtotime($row["bDatetime"]); 
if (date("I", $timestamp) == 1) { 
    $offset = 25200; 
} else { 
    $offset = 28800; 
} 
$_pubdate = date("r", $timestamp - $offset); 
+0

让我们[在聊天中继续讨论](http://chat.stackoverflow.com/rooms/134122/discussion-between-miken32-and-iampariah)。 – miken32