how to format atom date time

Yaniv Golan picture Yaniv Golan · Nov 5, 2009 · Viewed 28.3k times · Source

I'm getting dates from feed in this format:

2009-11-04T19:55:41Z

I'm trying to format it using the date() function in PHP, but I get an error saying:

date() expects parameter 2 to be long, object given in /bla/bla.php

I tried using preg_replace() to remove the T and the Z, but still can't get it to work.

Answer

Josh Leitzel picture Josh Leitzel · Nov 5, 2009

strtotime is a wonderful function for converting date formats to Unix timestamps.

This will give you what you're after:

date('my format here', strtotime('2009-11-04T19:55:41Z'));