如何减去分钟 [英] How to Subtract Minutes

查看:105
本文介绍了如何减去分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送提醒电子邮件.我不想在Linux/Unix/BSD框上使用cron或在Windows上使用计划任务.

I want to send a reminder email.I don't want to use cron on Linux/Unix/BSD box or Scheduled Tasks on Windows.

我正在尝试从当前时间中减去15分钟.

I'm trying to subtract 15 minutes from the current time.

到目前为止,这是我的代码(无效):

here is my code so far (doesn't work):

$days   = date("j",time());
$months = date("n",time());
$years  = date("Y",time());
$hours  = date("G",time());
$mins   = (date("i",time()));
$secs   = date("s",time());
$mins   = $mins-15;

推荐答案

将日期更改为时间戳(以秒为单位),然后减去15分钟(以秒为单位),然后转换回日期:

Change the date into a timestamp (in seconds) then minus 15 minutes (in seconds) and then convert back to a date:

$date = date("Y-m-d H:i:s");
$time = strtotime($date);
$time = $time - (15 * 60);
$date = date("Y-m-d H:i:s", $time);

这篇关于如何减去分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆