简体   繁体   English

使用strtotime减去日期后的分钟

[英]Subtract minutes from date using strtotime

I have the current date format $date = 'yyyy-mm-dd hh:mm' and notice that $date is already set and not using the Date class. 我有当前的日期格式$date = 'yyyy-mm-dd hh:mm' ,请注意,已经设置了$date而不使用Date类。 I understand I have to use strtotime which I have done to my $date $datestr = strtotime($date) . 我知道我必须使用strtotime ,它已经对$date $datestr = strtotime($date) I wish to subtract 5 minutes to the set time. 我希望减去设置的时间5分钟。


I've tried this simple thing $A = strtotime($date) - strtotime('-5 min'); 我已经尝试过这个简单的事情$A = strtotime($date) - strtotime('-5 min'); But it does not aid me. 但这对我没有帮助。

its simple to subtract the seconds of 5 minutes which is (5*60)=300 from your time 从您的时间中减去seconds of 5 minutesseconds of 5 minutes (5*60)=300很简单

like this 像这样

$time = strtotime($date);
$time_new = $time-(5*60); // will time of the -5 min from the current $time

example

$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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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