How to display a date as iso 8601 format with PHP
How to display a date as iso 8601 format with PHP
UNIX timestamp is the second argument of date,
We have to convert the database timestamp to strtotime() function.
<?= date("c", strtotime($post[3])) ?>
The DateTime class can be used for display a date as iso 8601 format with PHP. It is available in the PHP version 5.2 and later.
$datetime = new DateTime('17 Oct 2008'); echo $datetime->format('c');
If we have PHP 5.4 , achieve this simple one liner.
echo (new DateTime('17 Oct 2008'))->format('c');
Here is the easy and better function for pre PHP 5.
function iso8601($time=false) { if(!$time) $time=time(); return date("Y-m-d", $time) . 'T' . date("H:i:s", $time) .'+00:00'; }