[英]convert date from rss feed
I am trying to format a date from an RSS feed using the following code: 我正在尝试使用以下代码从RSS feed格式化日期:
foreach ($xml->channel->item as $item) {
$originalDate = trim($item->pubDate);
$newDate = date("d-m-Y", strtotime($originalDate));
var_dump($newDate);
}
The format of the date is Fri, 03 Aug 2012 13:08:11 UT
which comes from $item->pubDate
. 日期的格式为Fri, 03 Aug 2012 13:08:11 UT
,该日期来自$item->pubDate
。 Unfortunately this code does not work and the result are "31-12-1969"
How do I get the proper date? 不幸的是,该代码无法正常工作,结果为"31-12-1969"
如何获取正确的日期?
Since you don't seem to need the time anyways, and just the date, this works for me: 由于您似乎并不需要时间,也不需要日期,因此这对我有用:
$newDate = date("d-m-Y", strtotime(str_replace("UT", "", $originalDate)));
PHP doesn't seem to recognize the UT part. PHP似乎无法识别UT部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.