这是我的代码,
<script type="text/javascript">
function today(hour, minute) {
var now = new Date();
now.setHours(hour);
now.setMinutes(minute);
now.setSeconds(0);
now.setMilliseconds(0);
return now.getTime();
}
var now = new Date();
now = now.getTime();
if(
(now > today(11, 45) && now < today(14, 00)) ||
(now > friday(19, 00) && now < saturday(0, 00))
) {
alert("Lunchtime Specials!");
window.location = "http://google.ie";
}</script>
它适用于“今天”,但不是星期五或星期六等 有什么建议吗?
答案 0 :(得分:1)
你只想查看星期五的哪一天,然后是什么时间,以便获得星期五的一天:
var d = new Date();
var day = d.getDay();
if(day == 5){
alert("It's Friday!");
}
getDay()返回星期几(从0-星期日到6-sat)
如果您想查看一小时或一分钟,请执行以下操作(从顶部代码开始):
var hour = d.getHours();
if(hour == 11){
alert("It's 11 AM! Woo");
}
有关日期对象的完整文档,请查看此处:
http://www.tizag.com/javascriptT/javascriptdate.php