Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert an ISO8601 date to another format in PHP?

Facebook outputs dates in ISO8601 format - e.g.: 2011-09-02T18:00:00

Using PHP, how can I reformat into something like: Friday, September 2nd 2011 at 6:00pm

Nb - I was doing it in Javascript, but IE has date bugs so I want a cross-browser solution.

like image 980
user801347 Avatar asked Jun 23 '11 18:06

user801347


1 Answers

A fast but sometimes-unreliable solution:

$date = '2011-09-02T18:00:00';

$time = strtotime($date);

$fixed = date('l, F jS Y \a\t g:ia', $time); // 'a' and 't' are escaped as they are a format char.

Format characters detailed here.

like image 92
Marc B Avatar answered Oct 11 '22 04:10

Marc B