php - 如何将丢失的时间从另一个用 PHP 格式化(H:i:S)的时间变为微秒?
问题描述
我是stackOverflow的新手,我想知道如何从另一个微时间(真)开始将丢失的时间日期设置为微时间(真),并将其格式化为这样(H:i:s)。这是我的代码:
$rewardCountdown = microtime(true) - $this->dailyRewardTime; // daily reward is another microtime(true)
$rewardAvailable = $rewardCountdown >= 60 * 60 * 24; // check if 24h are gone so we can get reward
基本上我想以这种格式(H:i:s)获得$rewardCountdown,我尝试过并且以某种方式得到了类似的东西,但我的时间增加而不是减少
解决方案
当前microtime
减去前一个microtime
将是两个时间之间经过的秒数的正值。
如果要将秒转换为小时、分钟和秒,只需使用gmdate
.
$rewardCountdown = microtime(true) - $this->dailyRewardTime;
$date = gmdate('H:i:s', $rewardCountdown);
推荐阅读
- node.js - 如何防止数据库中重名但同一人可以上两门课程
- jenkins - Jenkins:从 GitHub 网络钩子触发构建的作业仅在主节点上运行
- java - 将 Timescale DB 的 Gapfill 与 JOOQ 一起使用会抛出参数:start 不能为 NULL
- java - 断开连接后自动删除kafka消费者组
- kubernetes - 重新部署 Kubernetes 集群时,如何保持客户端证书有效?
- flask - 使用发送将引导按钮链接到 Flask 中的 url
- javascript - 为授权代码流保护客户端机密的最佳方法
- android - Android studio 3.6.1 gradle 同步太慢
- javascript - 使用 vanilla javascript ajax [ASP.NET Core] 在同一个 POST 请求中上传文件和 Json 数据
- kubernetes - 使用 helm 将现有卷附加到 postgres slave