php如何进行时间的格式转换

时间:2026-02-14 09:15:57

1、打开PHPstudy,开启集成开发环境,创建test.php文件,并用notepad++打开。

php如何进行时间的格式转换

php如何进行时间的格式转换

php如何进行时间的格式转换

2、首先是最常用的时间戳与规定时间格式之间的互相转换:

//获取时间戳

$time = time();

echo $time;

echo '<br>';

//转换为年月日时分秒格式

$formatTime=date('Y-m-d H:i:s',time());

echo $formatTime;

echo '<br>';

$nowtime=strtotime($formatTime);

echo $nowtime;

php如何进行时间的格式转换

3、打开浏览器可以发现我们将时间戳转换成年月日时分秒格式的时间了,又把年月日时分秒格式的时间转换成时间戳了。

php如何进行时间的格式转换

4、然后是一些常用的获取时间戳方式:

echo "一个小时后的时间戳:".strtotime("+1 hours")."<br>";

echo "明天的时间戳:".strtotime("+1 day")."<br>";

echo "下星期的时间戳:".strtotime("+1 week")."<br>";

echo "下星期日的时间戳:".strtotime("next Sunday")."<br>";

echo "一个小时前的时间戳:".strtotime("-1 hours")."<br>";

echo "咋天的时间戳:".strtotime("-1 day")."<br>";

echo "上星期的时间戳:".strtotime("-1 week")."<br>";

echo "上星期日的时间戳:".strtotime("last Sunday");

php如何进行时间的格式转换

5、访问浏览器可以看到输出的时间戳。

php如何进行时间的格式转换

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com