<?php
// 获取当前时间戳
$timestamp = time();
echo "当前时间戳: " . $timestamp . "\n";
// 将时间戳转换为可读日期格式
$date = date("Y-m-d H:i:s", $timestamp);
echo "转换为日期格式: " . $date . "\n";
// 将日期字符串转换为时间戳
$dateString = "2023-10-05 14:30:00";
$timestampFromDateString = strtotime($dateString);
echo "从日期字符串转换的时间戳: " . $timestampFromDateString . "\n";
// 计算两个时间戳之间的差值(秒)
$timestamp1 = strtotime("2023-10-01 00:00:00");
$timestamp2 = strtotime("2023-10-05 14:30:00");
$differenceInSeconds = $timestamp2 - $timestamp1;
echo "两个时间戳之间的差值(秒): " . $differenceInSeconds . "\n";
// 计算两个时间戳之间的差值(天)
$differenceInDays = floor($differenceInSeconds / (60 * 60 * 24));
echo "两个时间戳之间的差值(天): " . $differenceInDays . "\n";
?>
time()
函数可以获取当前的 Unix 时间戳,即从1970年1月1日到现在的秒数。date()
函数可以将时间戳转换为指定格式的日期字符串。strtotime()
函数可以将日期字符串转换为时间戳。上一篇:php pathinfo
下一篇:php代码在线运行
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站