How to display a date as iso 8601 format with PHP
You can use the date() function in PHP to display a date in ISO 8601 format.
You can use the DateTime class in PHP to display a date in ISO 8601 format. The format string for ISO 8601 is Y-m-d\TH:i:sP. Here is an example of how to use it:
Example of displaying a date as iso 8601 format with PHP
<?php
$date = new DateTime();
echo $date->format('Y-m-d\TH:i:sP');Info
Watch a video course: Learn object oriented PHP
PHP provides both the procedural date() function and the object-oriented DateTime class for formatting dates. The example above uses DateTime::format(), which is the modern OOP approach and generally preferred for its flexibility and timezone handling.
This will output the current date and time in the ISO 8601 format, for example: "2022-09-22T14:44:11+00:00"