PHP时间戳:
- 表示从 1970年1月1日 00:00:00 到当前时间的秒数之和。
time()函数:
- 取得服务器当前时间的时间戳。
echo time();
时间差:
sleep()
函数:延迟执行当前脚本若干秒。$_SERVER['REQUEST_TIME']
:当前页面开始运行时的时间戳。- 在当前页面运行结束时将
time() - $_SERVER['REQUEST_TIME']
- 得到的就是当前页面运行的时间(秒):
- 在当前页面运行结束时将
sleep(2);
$xxoo = time() - $_SERVER['REQUEST_TIME'];
echo '页面运行时间:',$xxoo,' 秒';
//输出结果:页面运行时间:2 秒
//2017-1-1与2018-1-1的时间差
echo abs(strtotime("2017-1-1")-strtotime("2018-1-1"))/60/60/24
//输出结果:365
strtotime函数:
- 将任何字符串的日期时间描述解析为 Unix 时间戳。
echo strtotime("2018-1-1 16:00:10"); //输出 1514793610
echo strtotime("10 September 2018"); //输出 1536508800
echo strtotime("+1 day"); //输出明天此时的时间戳
mktime()函数:
- 取得一个日期的 Unix 时间戳
echo mktime(21, 50, 55, 07, 14, 2010);
//输出结果:1279115455
mktime()
在做日期计算和验证方面很有用,它会自动计算超出范围的输入的正确值:
echo date("Y-m-d", mktime(0, 0, 0, 12, 32, 2017));
echo "、";
echo date("Y-m-d", mktime(0, 0, 0, 13, 1, 20017));
//输出结果:2018-01-01、20018-01-01
Comments | NOTHING