迄今为止增加30分钟[已关闭]
所以我需要做的是在下面添加30分钟
date("Ymdhis");
我试过这个
+strtotime("+30 minutes");
然而,它似乎不喜欢它。我想知道这样做的正确原因是什么。
所以我需要做的是在下面添加30分钟
date("Ymdhis");
我试过这个
+strtotime("+30 minutes");
然而,它似乎不喜欢它。我想知道这样做的正确原因是什么。
您的使用方法应该有效。strtotime
<?php
echo date("Y/m/d H:i:s", strtotime("now")) . "\n";
echo date("Y/m/d H:i:s", strtotime("+30 minutes"));
?>
输出
2012/03/22 10:55:45
2012/03/22 11:25:45 // 30 minutes later
但是,您添加时间的方法可能不正确。上述内容将在当前时间的基础上增加 30 分钟。假设你想从给定时间添加 30 分钟,然后使用 的第二个参数,该参数用作计算相对日期的基础。$t
strtotime
date("Y/m/d H:i:s", strtotime("+30 minutes", $t));
我测试了这段代码,但它对我不起作用:
$t = date();
date("Y/m/d h:i:s", strtotime("+30 minutes", $t));
这是我的解决方案
//This is where you put the date, but I use the current date for this example
$date = date("Y-m-d H:i:s");
//Convert the variable date using strtotime and 30 minutes then format it again on the desired date format
$add_min = date("Y-m-d H:i:s", strtotime($date . "+30 minutes"));
echo $date . "<br />"; //current date or whatever date you want to put in here
echo $add_min; //add 30 minutes