Home > Article > Backend Development > How to Format a PHP Timestamp into a Human-Readable Date and Time?
PHP Timestamp Conversion: Retrieving Readable Date and Time
Users often encounter the need to convert numerical timestamps into human-readable date and time formats. This article addresses such a scenario where an individual seeks to convert a timestamp stored in a session (1299446702) to a more interpretable format in PHP.
The user initially attempted to utilize the strtotime function without success. However, the appropriate solution lies in employing PHP's date() function. This versatile function allows for the efficient conversion of timestamps into a wide range of date/time formats.
To illustrate its usage, consider the following code snippet:
<code class="php">echo date('m/d/Y', 1299446702);</code>
This line of code utilizes the date() function to format the given timestamp (1299446702) in the "m/d/Y" format, resulting in an output such as "09/06/2011". The specific format used can be customized to meet the desired requirements of the application.
The above is the detailed content of How to Format a PHP Timestamp into a Human-Readable Date and Time?. For more information, please follow other related articles on the PHP Chinese website!