【问题标题】:How to deduct time in php 24 hours format如何以 php 24 小时格式扣除时间
【发布时间】:2017-08-14 01:52:40
【问题描述】:

如何用 1 小时减去 00:00:00 示例?

我试过了:

$minus1=strtotime(00:00:00)-strtotime('-1 hour');

但我得到的不是23:00:00 的答案,而是-1502671524

【问题讨论】:

  • 也许尝试将您的 strtotime() 结果格式化为所需的时间格式?你看过在线手册date()吗?
  • PHP datetime sub issue的可能重复

标签: php date time


【解决方案1】:

您可以在 PHP 中使用 DateTime 和 DateInterval 选项。

$date = new DateTime('00:00:00'); $date->sub(new DateInterval('PT1H00M')); 回声 $date->format('H:i:s') 。 "\n";

P 代表周期。 T 代表时间跨度。 H 代表 Hour to reduce,最后 M 代表 Minutes to reduce。

请参阅 PHP 手册中的 DateTimeDateTime::subDateInterval。当然,您必须将DateTime 设置为适当的日期和时间。

【讨论】:

    猜你喜欢
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2012-06-04
    • 2017-08-07
    • 2020-02-23
    • 1970-01-01
    相关资源
    最近更新 更多