php - 添加两个小时至今的变量 [英] php - add two hours to date variable

查看:176
本文介绍了php - 添加两个小时至今的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个日期/时间变量3分钟,但我不知道如何做到这一点。
我从一个字符串中做出了这样的变量:(这是RFC 2822日期格式btw)

  $ date = 2011-10-18T19:56:00 + 0200 

I使用以下命令将该字符串转换为日期:

  $ time = date_format(DateTime :: createFromFormat(Ymd\TH:i :sO,$ date),G:i)

现在,我想添加3分钟到该变量,但我不知道如何。
我以前在我的脚本中使用了以下命令,但是这适用于当前的日期/时间,所以我不知道如何使用它作为我的时间变量:

  $ currenttime = date('G:i',strtotime('+ 2 hours')); 

那么如何在$ time变量中添加三分钟?

$ b $ echo 解决方案

  echo $ idate =2013-09-25 09:29:44 

$ effectiveDate = strtotime(+ 40 minutes,strtotime($ idate));

echo date(Y-m-d h:i:s,$ effectiveDate);


I want to add 3 minutes to a date/time variable I have, but I'm not sure how to do this. I made the variable from a string like this: (which is in the RFC 2822 date format btw)

$date = 2011-10-18T19:56:00+0200

I converted that string into date using this command:

$time = date_format(DateTime::createFromFormat("Y-m-d\TH:i:sO", $date), "G:i")

Now, I'd like to add 3 minutes to that variable, but I I'm not sure how. I've used the following command in my script before, but that applies to the current date/time, so I'm not sure how to use that for my time variable:

$currenttime = date('G:i', strtotime('+2 hours'));

So, how can I add three minutes to the $time variable?

解决方案

echo $idate="2013-09-25 09:29:44";

$effectiveDate = strtotime("+40 minutes", strtotime($idate));

echo date("Y-m-d h:i:s",$effectiveDate);

这篇关于php - 添加两个小时至今的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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