不要显示周末 [英] Dont display weekends

查看:80
本文介绍了不要显示周末的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看星期六或星期日,0或6使用getDay()== 1和getday()== 0,如果它不添加日期和时间到我的选择选项。



i want to see if day is Saturday or Sunday, 0 or 6 using getDay()==1 and getday()==0, if it is dont add the date and time to my select option.

    var from = new Date(firstNewDt);
    var to = new Date(start);
    var day = from.getDate();

    if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && from.getDay()==0||from.getDay()==1) {



            if (day <= 9) {
                day = "0" + day;
            }
            var month = from.getMonth() + 1;
            if (month <= 9) {

                month = "0" + month;
            }
            var year = from.getFullYear();
            var hours = from.getHours();
            if (hours < 10) {
                hours = "0" + hours;
            }

            var minutes = from.getMinutes();
            if (minutes < 30) {
                minutes = "0" + minutes;
            }


            var dayto = to.getDate();
            if (dayto <= 9) {
                dayto = "0" + dayto;
            }
            var monthto = to.getMonth() + 1;
            if (monthto <= 9) {
                monthto = "0" + monthto;
            }
            var yearto = to.getFullYear();
            var hoursto = to.getHours();
            if (hoursto < 10) {
                hoursto = "0" + hoursto;
            }
            var minutesto = to.getMinutes();
            if (minutesto < 30) {
                minutesto = "0" + minutesto;
            }



            bookedFreeTimes.push(year + "-" + month + "-" + day + " " + hours + ":" + minutes + " , " + yearto + "-" + monthto + "-" + dayto + " " + hoursto + ":" + minutesto);


        }

}





这里是我的代码我将我的值添加到数组然后显示它们。



现在如果我添加值2014-12-10 12:00到2014-12 -10 12:30



i然后从StartDate添加-5天,从Endate增加+5天,



所以我要求2014-12-05 12:00到2014-12-15 12:30

因此它不应该显示6,7 dec和13,14 dec所以现在它显示6月12日和13月12日,所以它不显示星期六,但星期天显示原因?



更新

==== =============

我应该这样吗?



Here is my code i add my values to an array and then display them.

Right now if i add the value 2014-12-10 12:00 to 2014-12-10 12:30

i then add days -5 from StartDate, and +5 days from Endate,

So i am quering from 2014-12-05 12:00 to 2014-12-15 12:30
so its should not display 6,7 dec, and 13,14 dec so right now it it dony display 6 dec and and 13 dec so its not displaying saturdays but sundays its displaying why?

UPDATE
=================
Should i have like this?

if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && (from.getDay() == 0||  from.getDay() == 1))





因为这样它仍然显示7月12日和12月12日



Because like this it still displays 7, and 14 december

推荐答案

&&优先于||所以,如果你不使用括号,因为你的意思是你得到了错误的条件检查!!!

在你的情况下你写了

&& has precedence over || so if you do not use parentheses as you mean you get the wrong condition check!!!
In your case you wrote
if(a && b && c && d || e)



等于


which is equal to

if((a && b && c && d) || e)



但可能你的意思是


but probably you meant

if(a && b && c && (d || e))


引用:

我想看看是否是星期六或星期日,0或6使用getDay()== 1和getday()== 0,如果它不会在我的选择选项中添加日期和时间。

i want to see if day is Saturday or Sunday, 0 or 6 using getDay()==1 and getday()==0, if it is dont add the date and time to my select option.



那么你的条件将是


then your conditions would be

if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && !(from.getDay() ==0 || from.getDay()==6)) {





请注意,您必须使用括号并更改 from.getDay ()== 1 from.getDay()== 6


这篇关于不要显示周末的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆