php - 3 位数的碳计数小时数
问题描述
我有一个应用程序可以从几条记录中计算小时数。现在我检测到如果小时数超过 2 位数的情况。
例如,我有一个$total = '102:00:00'
3 位数字,它返回给我这个错误:
A two digit minute could not be found
当我尝试这样做时会发生错误:Carbon::createFromFormat('H:i:s', $total);
我该如何解决这个问题?
谢谢
解决方案
I think you should not confuse a actual Date(Time) and a time interval. DateTime oriented function will not help you. Just create your own function to add two duractions. See (pseudo-)code below
function add_duration($h1,$m1,$s1,$h2,$m2,$s2)
{
$s3 = ($s1 + $s2)%60;
$m3 = ($m1 + $m2 + floor(($s1 + $s2)/60))%60;
$h3 = $h1 + $h2 + floor(($m1 + $m2 + floor(($s1 + $s2)/60))/60);
return [$h3,m3,s3];
}
推荐阅读
- python-3.x - Python:如何读取 csv 文件并存储在具有字符串键和浮点值的字典中
- mysql - 提取 SQL 表信息架构
- http - 在 gofiber POST 请求中,如何解析请求正文?
- bash - gStreamer:如何打印帧级 PTS
- laravel - 计划任务运行在 Laravel Window 10 中不起作用
- java - 试图在字符串中找到第二个整数 - 不工作
- laravel - 目录内的雄辩模型阻止了 Nova 导航中的资源可见性
- java - 无法从与另一个表具有多对多关系的表中删除行
- sql - SQLite 外键约束不抛出错误
- python - 为什么子类的init方法也会改变父类?