markzzz
markzzz

Reputation: 47947

What is the best way to parse a RSS pubDate in PHP?

I get a RSS and I manage it with PHP: I parse it, and I get the date value with :

$data_feed=$item[pubdate];

If I print this date, I get for example :

Wed, 05 Oct 2011 00:00:00 PST

I know that on RSS there are many date format, such as PST, EST, GMT, +0200 and son on.

How can I Parse on PHP any kind of date format from a RSS? As example, I'd like to have always the format DD-MM-YYYY.

Upvotes: 3

Views: 3838

Answers (2)

Jadamec
Jadamec

Reputation: 923

This simple command works for me:

$date = date_create_from_format(DateTime::RSS, $string);

Upvotes: 4

Brad Christie
Brad Christie

Reputation: 101594

strtotime will handle most common formats.

From there, you can use strftime to display the format you'd like.

Upvotes: 5

Related Questions