2017-01-26 71 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