gpt4 book ai didi

php - 在php中添加两个或多个时间字符串

转载 作者:行者123 更新时间:2023-12-01 22:45:40 25 4
gpt4 key购买 nike

我有一个包含时间(字符串)的数组,例如“2:23”、“3:2:22”等

$times = array("2:33", "4:2:22", "3:22") //loner

我想找到所有数组的总和。

有没有办法可以添加像“2:33”和“3:33”(“i:s”)这样的时间

谢谢

最佳答案

您可能想看看 the PHP date/time functions - 一种选择是使用类似 strtotime() 的方法:

$midnight = strtotime("0:00");

// ssm = seconds since midnight
$ssm1 = strtotime("2:33") - $midnight;
$ssm2 = strtotime("3:33") - $midnight;

// This gives you the total seconds since midnight resulting from the sum of the two
$totalseconds = $ssm1 + $ssm2; // will be 21960 (6 hours and 6 minutes worth of seconds)

// If you want an output in a time format again, this will format the output in
// 24-hour time:
$formattedTime = date("G:i", $midnight + totalseconds);

// $formattedTime winds up as "6:06"

关于php - 在php中添加两个或多个时间字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1370332/

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