php 将分钟添加到 strtotime

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20061727/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:50:08  来源:igfitidea点击:

Add minutes to strtotime

phpstrtotime

提问by Shawn Sonnier

If i have a varible

如果我有一个变量

// in minutes
$min = 40;

And i want to add it to a strotime formatted time

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

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

whats the correct way to do this?

这样做的正确方法是什么?

回答by Rocket Hazmat

You can do this:

你可以这样做:

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

回答by John Conde

There's not much to it:

没什么可说的:

echo strtotime("+40 minutes");

See it in action

看到它在行动

回答by Sverri M. Olsen

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);

回答by Ugokoli

$min = 40;

And i want to add it to a strotime formatted time

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

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