When working with timestamps in PHP, it is often necessary to convert them into human-readable date strings. This is particularly useful for displaying dates and time in a consistent and visually appealing format. One common date format used is the ISO 8601 format, which expresses dates and times in the form:
YYYY-MM-DD[T]hh:mm:ss[Z][+/-hh:mm]
In this format, the Z suffix indicates that the time is in UTC (Coordinated Universal Time).
To convert a UNIX timestamp to an ISO 8601-formatted date string, you can use the gmdate() function in PHP. The gmdate() function takes two arguments: a date format string and a timestamp.
For example, to convert the UNIX timestamp 1333699439 to an ISO 8601-formatted date string, you would use the following code:
$timestamp = 1333699439; echo gmdate("Y-m-d\TH:i:s\Z", $timestamp);
This would output the date string:
2008-07-17T09:24:17Z
The Y-m-dTH:i:sZ format string specifies the following date format elements:
The above is the detailed content of How to Convert UNIX Timestamps to ISO 8601 Formatted Date Strings in PHP?. For more information, please follow other related articles on the PHP Chinese website!