In PHP, you can use the date() function to convert a PHP timestamp to a human-readable date: use the date(string $format, int $timestamp = time()) function. Provide the $format parameter to specify the format of the output date. Optionally provide the $timestamp parameter to specify the UNIX timestamp to convert, which defaults to the current time.
Convert PHP timestamp to human-readable date
In PHP you can use date( )
Function converts a UNIX timestamp to a human-readable date.
Syntax:
date(string $format, int $timestamp = time())
Parameters:
Actual case:
<?php // 获取当前时间戳 $timestamp = time(); // 将时间戳转换为日期字符串 $dateString = date("Y-m-d H:i:s", $timestamp); // 输出日期字符串 echo $dateString; ?>
Output:
2023-03-07 13:40:15
In addition to using date()
function, you can also use the following function:
gmdate():
Convert the timestamp to Greenwich Mean Time (GMT) format. strftime():
Use a more advanced format string to format dates. Tip:
DateTime
class. The above is the detailed content of Convert php timestamp to human readable date. For more information, please follow other related articles on the PHP Chinese website!