PHP 日期时间当前时间添加分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/985818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Date Time Current Time Add Minutes
提问by Ervin Ter
Simple question but this is killing my time.
简单的问题,但这正在消磨我的时间。
Any simple solution to add 30 minutes to current time in php with GMT+8?
有什么简单的解决方案可以使用 GMT+8 在 php 中将当前时间添加 30 分钟?
回答by Khriz
I think one of the best solutions and easiest is:
我认为最好和最简单的解决方案之一是:
strtotime("+30 minutes")
Maybe it's not the most efficient but is one of the more understandable.
也许它不是最有效的,但它是更容易理解的方法之一。
回答by mns
This is an old question that seems answered, but as someone pointed out above, if you use the DateTime class and PHP < 5.3.0, you can't use the add method, but you can use modify:
这是一个似乎已回答的老问题,但正如上面有人指出的那样,如果您使用 DateTime 类和 PHP < 5.3.0,则不能使用 add 方法,但可以使用modify:
$date = new DateTime();
$date->modify("+30 minutes"); //or whatever value you want
回答by MaxEcho
Time 30 minutes later
时间 30 分钟后
$newTime = date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")." +30 minutes"))
回答by Stefan Gehrig
$timeIn30Minutes = mktime(idate("H"), idate("i") + 30);
or
或者
$timeIn30Minutes = time() + 30*60; // 30 minutes * 60 seconds/minute
The result will be a UNIX timestamp of the current time plus 30 minutes.
结果将是当前时间加上 30 分钟的 UNIX 时间戳。
回答by sarah
echo $date = date('H:i:s', strtotime('13:00:00 + 30 minutes') );
13:00:00 - any inputted time
13:00:00 - 任何输入的时间
30 minutes - any interval you wish (20 hours, 10 minutes, 1 seconds etc...)
30 分钟 - 您希望的任何间隔(20 小时、10 分钟、1 秒等...)
回答by a_m0d
It looks like you are after the DateTime function add - use it like this:
看起来你在 DateTime 函数添加之后 - 像这样使用它:
$date = new DateTime();
date_add($date, new DateInterval("PT30M"));
(Note: untested, but according to the docs, it should work)
(注意:未经测试,但根据文档,它应该可以工作)
回答by priya
$ck=2016-09-13 14:12:33;
$endtime = date('H-i-s', strtotime("+05 minutes", strtotime($ck)));
回答by Faysal Ahammed
time after 30 min, this easiest solution in php
30 分钟后的时间,这是 php 中最简单的解决方案
date('Y-m-d H:i:s', strtotime("+30 minutes"));
for DateTime class (PHP 5 >= 5.2.0, PHP 7)
对于 DateTime 类(PHP 5 >= 5.2.0,PHP 7)
$dateobj = new DateTime();
$dateobj ->modify("+30 minutes");
回答by Lawrence Cherone
The question is a little old, but I come back to it often ;p
这个问题有点老了,但我经常回到它;p
Another way, which is also a one liner:
另一种方式,这也是一个班轮:
<?= date_create('2111-11-11 00:00:00')->modify("+30 minutes")->format('Y-m-d h:i:s') ?>
Or from timestamp, returns Y-m-d h:i:s:
或者从时间戳,返回 Ymd h:i:s:
<?= date_create('@'.time())->modify("+30 minutes")->format('Y-m-d h:i:s') ?>
Or from timestamp, returns timestamp:
或者从时间戳,返回时间戳:
<?= date_create('@'.time())->modify("+30 minutes")->format('U') ?>
回答by swastika polley
$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
echo $dateTime->modify("+10 minutes")->format("H:i:s A");

