Home >Backend Development >PHP Tutorial >How to Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP?
Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP
Converting UNIX timestamps into formatted date strings like "2008-07-17T09:24:17Z" in PHP requires a simple technique. To transform a timestamp into this format, follow these steps:
PHP Implementation Using gmdate() Function
The gmdate() function provides a straightforward way to achieve this conversion. It takes a timestamp as an argument and returns a formatted date string according to the specified format. To obtain the ISO 8601 format, use the following syntax:
gmdate("Y-m-d\TH:i:s\Z", $timestamp);
Where:
Example:
Consider the timestamp 1333699439. Using the gmdate() function, you can convert it to an ISO 8601 string as follows:
$timestamp=1333699439; echo gmdate("Y-m-d\TH:i:s\Z", $timestamp);
This will output the result: "2008-07-17T09:24:17Z".
The above is the detailed content of How to Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP?. For more information, please follow other related articles on the PHP Chinese website!