php - How to add different timestamp
问题描述
I'm having a problem adding two(2) timestamp for example:
00:30:00
00:45:31
========
01:15:31
I can't figure it out how to do it using laravel with carbon...
解决方案
You can't add time like they are integer. One of the way is to convert it to another format and then add it. After adding them, convert it back to time type.
For example, try this:
$time1 = "00:30:00";
$time2 = "00:45:31";
$secs = strtotime($time2) - strtotime("00:00:00");
$result = date("H:i:s", strtotime($time1) + $secs);
dd($result); // "01:15:31"
推荐阅读
- java - yml - 多个键映射到相同的值
- java - 为什么我无法格式化其他两个国家的货币中国和法国
- android - AOSP ninja build 已停止:子命令失败
- mpeg - 解码图片缓冲区和编码图片缓冲区有区别吗?
- azure - 如何使用 Azure Active Directory (AAD) 从 Azure blob 将数据读入数据块笔记本
- pointers - 为什么在 Fortran 中对不相关的整数变量调用 write 会释放无限多态指针?
- java - 具有通用服务的 Spring Boot 映射器
- reactjs - 如何访问 redux 状态的初始值?
- php - 由于标准定义错误,无法通过 PHP / google-sheets-API 过滤 Google 表格(“无法将列表绑定到映射字段‘标准’”)
- javascript - dom-to-image.js 不生成图像