The current output time is also the number of minutes ending with the specified number of minutes, for example, 714: 56: 21-& amp; gt; 14: 57: 0014: 57: 21-& amp; gt; at 15:07:00, I wrote a message about it. {code ...} the output time is also the number of minutes that end with the specified minute-end,
For example, 7 14:56:21-> 14:57:00
14:57:21> 15:07:00
It's not easy to write it yourself.
function get_minutes($dest){ $start1 =new DateTime(); $date = $start1 ->format('Y-m-d-H-i-s'); list($year,$mon,$day,$hour,$min,$sec) = explode('-',$date); $start2 = new DateTime($year.'-'.$mon.'-'.$day.' '.$hour.':'.$min); $needle = floor($min/10)*10 +$dest; $needle = $needle > $min ? $needle : $needle +10; $extra = $needle - $min; $timestr = '+ '.$extra.' minutes'; $start2->modify($timestr); return $start2->format('Y-m-d H:i:s');}echo get_minutes(7);
Reply content:
The output time is also the number of minutes that end with the specified minute-end,
For example, 7 14:56:21-> 14:57:00
14:57:21> 15:07:00
It's not easy to write it yourself.
function get_minutes($dest){ $start1 =new DateTime(); $date = $start1 ->format('Y-m-d-H-i-s'); list($year,$mon,$day,$hour,$min,$sec) = explode('-',$date); $start2 = new DateTime($year.'-'.$mon.'-'.$day.' '.$hour.':'.$min); $needle = floor($min/10)*10 +$dest; $needle = $needle > $min ? $needle : $needle +10; $extra = $needle - $min; $timestr = '+ '.$extra.' minutes'; $start2->modify($timestr); return $start2->format('Y-m-d H:i:s');}echo get_minutes(7);
Let's analyze the requirements. the minutes are 7 minutes, 10 + 7 minutes, 20 + 7 minutes, 30 + 7 minutes, 40 + 7 minutes, and 50 + 7 minutes; in addition, the 7 score of 57 points to the next node is also 10 minutes different.
This is because the total number of seconds from January 1, January 01, 1970 to GMT.
The first 7 minutes is 420 seconds, followed by an increase of 600 seconds.
The number of seconds to be supplemented is: first divide the current time by the remainder of 600. if it is less than 420, it is directly reduced by 420. if it is greater than 600, it is reduced by 420 +.
$time = time();echo date('Y-m-d H:i:s',$time);$last = $time%600;$last = $last<420?420-$last:1020-$last;echo '
';echo date('Y-m-d H:i:s',$time+$last);
Function get_minutes ($ dest) {if ($ dest> = 10) {throw new Exception ('param error! ') ;}$ Mitute = date (' I '); $ unit = $ mitute % 10; // The number of minutes in a single position $ offset = $ dest-$ unit; if ($ dest <= $ unit) {$ offset + = 10;} return date ('Y-m-d H: I: 00', strtotime ('+ '. $ offset. 'minutes ');} echo get_minutes (7 );
Strange requirements ..
I think your code is a bit complicated. In fact, the idea is very simple.
It is to check whether the number of single digits in a minute is greater than 7. if the number is greater than 7, 17-single digits are used. otherwise, 7-single digits are used. the result is the difference between the number of minutes with the next Ending number of 7 and the current minute. and then add the difference?
$date = new DateTime();$minute = $date->format('i');$diff_minute = $minute[1] >= 7 ? (17 - $minute[1]) : (7 - $minute[1]);$date->add(new DateInterval("PT" . $diff_minute . 'M'));echo $date->format('Y-m-d H:i:s');
Here is an example. for convenience, the 7 Hard code is included. you can change the code as needed.