要将当前时间戳转换为可读的日期和时间格式,可以使用date()函数。以下是一个示例:
$currentTimestamp = time();
$dateTime = date('Y-m-d H:i:s', $currentTimestamp);
echo $dateTime;
这将输出当前时间的日期和时间,例如:2022-01-01 12:34:56。
要计算两个时间戳之间的差异,可以将它们相减。以下是一个示例:
$timestamp1 = time(); // 第一个时间戳
$timestamp2 = strtotime('2022-01-01 00:00:00'); // 第二个时间戳
$difference = $timestamp1 - $timestamp2;
echo "时间戳差异:".$difference." 秒";
这将输出两个时间戳之间的差异,以秒为单位。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站