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 04 Answers
Reset to default 5function 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
版权声明:本文标题:php - how to check current time is a multiple of five minutes in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744061790a2584260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论