Converting Timestamps to Human-Readable Date/Time in PHP
Problem:
You have a timestamp stored in a PHP session and want to display it as a human-readable date and time. However, the standard PHP date functions, such as strftime and strtotime, have not been successful in this task.
Solution:
To convert a timestamp to a readable date/time in PHP, use the date() function. This function takes the timestamp as an argument and returns a formatted date and time string according to the specified format.
Example:
Here's how to convert a timestamp of 1299446702:
<code class="php">echo date('m/d/Y', 1299446702);</code>
This code will output "12/28/2010", which is the date and time represented by the provided timestamp.
Customization:
You can customize the format of the date and time string by passing different format specifiers to the date() function. Common format specifiers include:
For example, the following code will output "December 28, 2010 12:00 AM":
<code class="php">echo date('F j, Y g:i A', 1299446702);</code>
The above is the detailed content of How to Convert Timestamps to Human-Readable Date/Time in PHP?. For more information, please follow other related articles on the PHP Chinese website!