简体   繁体   中英

Add minutes to strtotime

If i have a varible

// in minutes
$min = 40;

And i want to add it to a strotime formatted time

$strtTime = $strtotime('now') + $min; 

whats the correct way to do this?

你可以这样做:

strtotime("+{$min} minutes");

There's not much to it:

echo strtotime("+40 minutes");

See it in action

Well, look at the documentation . It tells you how to use the function.

$future = strtotime('+40 minutes');

You can also be a little more concrete and include where to start from.

$future = strtotime('now + 40 minutes');

While the above is a lot easier you could also do it manually. It just involves some basic arithmetic:

$now     = time(); // Seconds since 1970-01-01 00:00:00
$minutes = 40;
$seconds = ($minutes * 60); // 2400 seconds
$future  = ($now + $seconds);
$min = 40;

我想将其添加到strotime格式化的时间

$strtTime = strtotime("+".$min." minutes", strtotime('now'));//eg +40 minutes 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM