PHP 获取零点时间戳

PHP 获取零点时间戳

百度一下,大都这样 echo strtotime(date("Y-m-d"), time()); 我也是醉了。

其实这里有简单不用去多嵌套一个函数

echo strtotime('midnight');

PHP strtotime 函数还有很多用法, 例如 获取下个月一日的时间,下周一的时间错等...

// 下个月1日零点 时间戳
echo strtotime('midnight first day of next month');

// 3个月后的1日零点 时间戳
echo strtotime('midnight first day of +3 month');

// 3个月后的今日零点 时间戳
echo strtotime('midnight +3 month');

// 3个月后的今日 时间戳 (对应当前时间)
echo strtotime('+3 month');

// 下周一零点 时间戳
echo strtotime('next monday midnight');

能实现还有还跟多, 具体见 https://www.php.net/manual/zh/function.strtotime.php

进行上面操作的时候要先确认 PHP 的时区设置正确。

如果本文让你感觉受益匪浅,那就说明 PHP 官方手册你看的还是少

Post Author: admin