whatf
whatf

Reputation: 6458

parsing date IETF RFC 3339 in php

could anyone please explain how to parse date in IETF RFC 3339 in php, in most convenient method. an example of date in the above format is : 2011-03-14T06:25:22+0000

thanks!!

Upvotes: 0

Views: 4539

Answers (2)

Charles
Charles

Reputation: 51411

At least as of PHP 5.3, that format is natively supported by strtotime and date_create. Using a DateTime from the PHP interactive shell:

php > $d = date_create('2011-03-14T06:25:22+0000');
php > echo $d->format('Y-m-d H:i:s');
2011-03-14 06:25:22
php > echo $d->getTimezone()->getName();
+00:00

You'll probably want to read up on all of the formats these two functions support.

Upvotes: 1

jrn.ak
jrn.ak

Reputation: 36619

Using strtotime() and date() ...

<?php
    // source date
    $source = strtotime('2011-03-14T06:25:22+0000');

    // remove this line to use your server's local time
    date_default_timezone_set('UTC');

    // parse and print
    echo date('Y-m-d h:i.s A O', $source);
?>

Output:

2011-03-14 06:25.22 AM +0000

Upvotes: 0

Related Questions