以下是使用 PHP 将天、分钟、小时和秒添加到时间的非常简单的方法。使用 date 函数设置要返回的日期格式,然后使用 strtotime 添加时间的增加或减少,然后在逗号后使用另一个 strtotime 传递开始日期和时间。

//set timezone
date_default_timezone_set('GMT');

//set an date and time to work with
$start = '2014-06-01 14:00:00';

//display the converted time
echo date('Y-m-d H:i',strtotime('+1 hour +20 minutes',strtotime($start)));

可以以可读的方式输入时间:

  • +1 天 = 增加 1 天
  • +1 小时 = 增加 1 小时
  • +10 分钟 = 增加 10 分钟
  • +10 秒 = 增加 10 秒

要减去时间,除了使用 – 而不是 + 之外,它是相同的

发表回复

您的电子邮箱地址不会被公开。