Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我敢肯定这个问题以前被问过,但我太沮丧了,找不到它。我想做的就是在 X 点钟上增加 X 分钟。
因此,以我为例,我有一个时间是早上 7:30,我想将 2:20(两分 20 秒)添加到该时间。(特别是那些格式)。
我什至以前也这样做过,但似乎每次我尝试散列一个新的 PHP 时间函数时,就好像我进入了格式错误的领域。感谢您的意见,我将在余生中为这个答案添加书签。
上午 7:30 增加 2 分 20 秒:
$dt = new DateTime('7:30 AM'); $dt->add(new DateInterval('PT2M20S')); echo $dt->format('H:i:s')."\n";
输出:
07:32:20
将其转换为时间戳,添加 600 秒并将其转换回来。