Converting UNIX Timestamps to Formatted Date Strings in PHP
In PHP, the gmdate function can be utilized to convert UNIX timestamps into date strings in a specific format. This function takes two arguments: the date format string and the timestamp to be converted.
To achieve the desired format of "2008-07-17T09:24:17Z", the following date format string can be used: "Y-m-dTH:i:sZ". The Z specifier indicates that the date should be represented in the ISO 8601 format, which includes a "Z" suffix to denote Coordinated Universal Time (UTC).
For example, to convert the timestamp 1333699439 to the desired format, the following code can be used:
<?php $timestamp=1333699439; echo gmdate("Y-m-d\TH:i:s\Z", $timestamp); ?>
This code will output the date string "2008-07-17T09:24:17Z", as requested.
The above is the detailed content of How to Convert UNIX Timestamps to Formatted Date Strings in PHP?. For more information, please follow other related articles on the PHP Chinese website!