1、打开PHPstudy,开启集成开发环境,创建test.php文件,并用notepad++打开。
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;
3、打开浏览器可以发现我们将时间戳转换成年月日时分秒格式的时间了,又把年月日时分秒格式的时间转换成时间戳了。
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");
5、访问浏览器可以看到输出的时间戳。