Home > Article > Backend Development > How to Convert Timestamps to Human-Readable Dates and Times in PHP?
Encountering difficulties in converting a timestamp stored in a PHP session into a legible date and time? In this article, we will address your query and guide you through a comprehensive solution. While methods like strttotime may not have yielded the desired results, PHP offers a powerful function specifically designed for this task.
To effortlessly convert a timestamp into a human-readable format, employ PHP's date() function. Its versatility allows you to specify a wide range of formatting options, ensuring that the resulting date and time adhere perfectly to your requirements.
Consider a timestamp of 1299446702, which represents a specific date and time. To convert this timestamp into a more comprehensible format, we can leverage the date() function as follows:
<code class="php">echo date('m/d/Y', 1299446702);</code>
The 'm/d/Y' portion of the date() function defines the desired output format, where 'm' represents the month as a numerical value ('01' for January, '02' for February, and so on), 'd' represents the day of the month (e.g., '01' for the first day), and 'Y' represents the full year (e.g., '2023').
Executing the above code will produce output in the format 'mm/dd/yyyy', displaying the human-readable date corresponding to the input timestamp.
The above is the detailed content of How to Convert Timestamps to Human-Readable Dates and Times in PHP?. For more information, please follow other related articles on the PHP Chinese website!