gpt4 book ai didi

php - php 中的时间计算(加 10 小时)?

转载 作者:IT王子 更新时间:2023-10-28 23:50:31 27 4
gpt4 key购买 nike

我得到时间:

$today = time();
$date = date('h:i:s A', strtotime($today));

如果当前时间是“1:00:00 am”,我如何再增加 10 小时成为 11:00:00 am?

最佳答案

strtotime() 为您返回一个数字,表示以秒为单位的时间。要增加它,请添加您要添加​​的相应秒数。 10 小时 = 60*60*10 = 36000,所以...

$date = date('h:i:s A', strtotime($today)+36000); // $today is today date

编辑:我假设您在 $today 中有一个字符串时间 - 如果您只是使用当前时间,那就更简单了:

$date = date('h:i:s A', time()+36000); // time() returns a time in seconds already

关于php - php 中的时间计算(加 10 小时)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1665702/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com