質問

I have a question that is making me crazy, My Task is to parse a date from an API and transform it to RFC 822 format, because the feed that is coming out gets an validation error

the date from the API looks like this :

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

I have one Date in the description made via 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; 

this date will be rendered like :

23.10.2012

For the pubdate I made

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

rendered like :

2012-10-23 14:51:12 GMT

And W3C feed validator says it´s not validate because pubDate is not in RFC 822 form

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>

and it needs to look like :

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

i can imagine a hacky solution for expressing sth like "if (month = 01){ actualmonth = Jan}" but i really don´t know how to do same with the days,

Also i´m not too comfortable with PHP but I need to solve this asap.

Hope you can help me, there must be a solution i didnt found at similiar questions

regards John

役に立ちましたか?

解決

Have a look at DateTime::createFromFormat() or 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');
?>

Have a look at the possible date formats

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

EDIT: fixed

他のヒント

Hi in PHP you should look at this: function date

yeaaaaah that worked for me, amazing!

for others the exact solution for my Case was


$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";

thanks a lot for the quick answers you are awesome!

This worked for me....

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

$yourdate was 2013-10-27 and I got Sun, 27 Oct 2013 00:00:00 +0000

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top