开发者

adding php time

i have a value store in variables as 11:30.

I need to add a minutes to this variable..Example, adding 15 minutes to make it 11:45

can i do that ? i tried to use time() but it will give current time... but开发者_开发百科 i want to add time to the specified variable


date("H:i", strtotime("11:30 +15 minutes"));


Try this way:

$time = "11:30";
$minutes = 15; 
$time = strtotime($time) + $minutes * 60;
echo date("H:i", $time);


Here's a way:

$str = "11:30";
list($h, $m) = explode(":", $str);
$tm = mktime($h, $m + 15, 0, 0, 0, 0);
echo date("H:i", $tm);


I think you can do what your asking for using the built in PHP methods mktime and date_add.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜