In PHP, you can use the date() function to convert the timestamp into an actual time. The function of this function is to format the timestamp into a more readable date and time. You can use parameters to specify The converted time format, the syntax is "date (timestamp format, specified timestamp)".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
PHP date() function can format timestamp into a more readable date and time.
Syntax
string date ( string $format [, int $timestamp ] )
The parameters are expressed as follows:
format Required. Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current date and time.
The first required parameter format of the date() function specifies how to format the date/time.
Here are some available characters:
d - represents the day of the month (01 - 31)
m - represents the month (01 - 12)
Y - represents the year (four digits)
If you need to know what is available in the format parameter For a list of all characters, please consult our PHP Date Reference Manual, date() function.
You can insert other characters between letters, such as "/", "." or "-", so that you can add additional formatting:
<?php echo date("Y/m/d") . "<br>"; echo date("Y.m.d") . "<br>"; echo date("Y-m-d"); ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert timestamp to actual time in php. For more information, please follow other related articles on the PHP Chinese website!