admin管理员组

文章数量:1356304

I want to know if the current time is a multiple of five. That means, I want to check if it is 8:30, 8:35, 8:40, .... is there any function in javascript or php that can do this?

I want to know if the current time is a multiple of five. That means, I want to check if it is 8:30, 8:35, 8:40, .... is there any function in javascript or php that can do this?

Share Improve this question asked Apr 9, 2013 at 10:27 ChrisChris 1,2784 gold badges17 silver badges25 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 5
function isFivesMultiple(){
    return new Date().getMinutes() % 5 == 0
}

what about 19:00?

in php it is:

if(date('i')%5==0){
    echo "the current date is a multiple of 5";
}

In javascript, get the current minutes (Date.getMinutes()) and check it is a multiple of 5 using the modulo (%) operator;

var date = new Date(2013,3,9,8,30)
alert(date.getMinutes() % 5 == 0); // alerts "true"

var date2 = new Date(2013,3,9,8,32)
alert(date2.getMinutes() % 5 == 0);  // alerts "false"
<?php
date_default_timezone_set('Asia/Kolkata');
$now=time();
$minute=date('i',$now);
if($minute>0)
{
    if($minute%5==0)
        echo 'true'.date('H:i',$now);
    else
        echo 'false'.date('H:i',$now);
}
else
{
    echo 'true'.date('H:i',$now);
}
?>

本文标签: phphow to check current time is a multiple of five minutes in javascriptStack Overflow