Hi All,
I’m taking a date from an RSS feed which is long and ugly “Thu, 23 Jun 2011 17:07:29 UT” and trying to change it to “June 23, 2011”. Usually I can muddle my way through things like this but I’m stumped here. After tons of googling and forum searching, here is the code that I’m working on:
$postdate = $this->pubdate;
echo $postdate;
print date('m/d/Y',strtotime($postdate));
Here’s the output:
Thu, 23 Jun 2011 17:07:29 UT12/31/1969
I’ve been at this for two days now and I’m at a loss, any help you could provide would be greatly appreciated!
I am assuming the “date” info is consistent i.e. the day comes first as a 3 letters followed by a comma and space, with the date as a 2-3-4 string. The following should help:
$date=“Thu, 23 Jun 2011 17:07:29 UT”;
$new_date=substr($date,5,11);
echo date(“M d, Y”,strtotime($new_date));
UT
is not a valid timezone, did you mean UTC
?
haha. I just wasted 15 minutes doing crazy regex and things:
preg_match("/([A-Za-z]+) ([0-9]{1,2}) ([A-Za-z]+) ([0-9]{2,4}) (([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})) ([A-Za-z]+)/",$postdate,$patternMatches);
echo date("F d, Y",strtotime($patternMatches[2]." ".$patternMatches[3]." ".$patternMatches[4]." ".$patternMatches[6].":".$patternMatches[7].":".$patternMatches[8]));
but you’re right - using the correct timezone fixes it. Then again, you can’t always be sure you’re getting given the right information. I know Amazon use some timezones they’ve basically made up themselves!
Salathe, that’s what I thought, but it is a date from a Google XML feed and that’s how it is listed?
Newton Police Department Press Group Google Group
Hess- Tried your code and it’s returning “December 31, 1969”
Universal Time (UT) 
<?php
function ut_to_time($ut){
return strtotime(substr($ut, 0, -3));
}
echo date('r', ut_to_time('Thu, 23 Jun 2011 17:07:29 UT'));
/* Thu, 23 Jun 2011 17:07:29 +0100 */
Anthony, is there a reason that using UT would cause an issue using date and strtotime?
I’d guess it doesn’t support UT in some way, shape or form.
There’s a few hits for it on Google’s cache of bugs.php.net, which is down right now. 
The author of the strtotime function marked this issue down as “Won’t Fix” and stated the following reason why:
Thanks for the info. I think for now I’ll just not show the post date and revisit the issue when I have more time to spend on the alternatives. Thanks everyone!
… but, don’t you have a solution now?
<?php
function ut_to_time($ut){
return strtotime(substr($ut, 0, -3));
}
echo date('F j, Y', ut_to_time('Thu, 23 Jun 2011 17:07:29 UT'));
/* June 23, 2011 */
For most uses (and I suspect almost certainly for tedleonard’s needs) UT(1) can be approximated with UTC, so making PHP think that the date is in UTC makes most sense in my book. Removing the timezone information in the date string and falling back on the default timezone (which may or may not be UTC) might also be okay, but it doesn’t sit well with me.
Adapting Anthony’s snippet, something like the following should be fine.
function ut_to_time($ut){
$utc = new DateTimeZone('UTC');
return date_create(substr($ut, 0, -3), $utc)->format('U');
}
Also, since I’m a big fan of the method, I’d probably use DateTime::createFromFormat()
.
function ut_to_time($ut){
$utc = new DateTimeZone('UTC');
return DateTime::createFromFormat('D, j M Y H:i:s ??', $ut, $utc)->getTimestamp();
}
I’d also like to throw this out there, but the Atom 1.0 version of those Google Groups feeds has a more sensible date format (e.g. 2011-06-23T17:07:29Z
).
I did convert it to UTC, but it added an hour to the time supplied. 