Home > Article > Backend Development > How to Convert a Timestamp into a Human-Readable Date/Time Format in PHP?
Convert Timestamps into Human-Readable Date/Time Format in PHP
When working with timestamps in PHP, it's often useful to convert them into a readable date and time format for display purposes. This article demonstrates how to convert a timestamp from a session variable into a user-friendly representation.
Query:
A user has a timestamp stored in a session (e.g., 1299446702) and wants to know how to convert it into a readable format.
Response:
To convert a timestamp into a readable date/time format in PHP, utilize the date() function. This function requires the timestamp as the first argument and a format string as the second argument.
Here's an example of how to convert the given timestamp (1299446702):
<code class="php">echo date('m/d/Y', 1299446702);</code>
Using the m/d/Y format string, the output will be in the following format: MM/DD/YYYY (e.g., 03/12/2011).
Additional Information:
The date() function provides various format options to customize the output. Some commonly used format specifiers include:
The above is the detailed content of How to Convert a Timestamp into a Human-Readable Date/Time Format in PHP?. For more information, please follow other related articles on the PHP Chinese website!