首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用strtotime从日期中减去分钟

使用strtotime从日期中减去分钟
EN

Stack Overflow用户
提问于 2014-02-17 08:27:55
回答 1查看 1.6K关注 0票数 0

我有当前的日期格式$date = 'yyyy-mm-dd hh:mm',并注意到已经设置了$date,并且没有使用Date类。我知道我必须使用strtotime,这是我对$date $datestr = strtotime($date)所做的。我想把5分钟减到规定的时间。

我试过这个简单的事情,$A = strtotime($date) - strtotime('-5 min');,但它对我没有帮助。

EN

回答 1

Stack Overflow用户

发布于 2014-02-17 08:29:28

从你的时间中减去seconds of 5 minutes,也就是(5*60)=300,很简单

像这样

代码语言:javascript
复制
$time = strtotime($date);
$time_new = $time-(5*60); // will time of the -5 min from the current $time

示例

代码语言:javascript
复制
$date = date('d-M-Y g:i:s A'); // current date
echo $date."<br/>"; // output : 17-Feb-2014 8:35:58 AM
$time = strtotime($date);     // convert current date to timestamp
$time_new = $time - (5*60);   // subtract 5 minutes from current time.
$date_new = date('d-M-Y g:i:s A', $time_new); // convert time to the date again
echo $date_new;  // output : 17-Feb-2014 8:30:58 AM 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21824070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档