确定日期是工作日/周末java [英] Determine if date is weekday/weekend java
本文介绍了确定日期是工作日/周末java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试比较星期几,如果是周末,请执行一项操作(尚未执行),但是如果我输入今天的日期25/11/2016或明天, 2016年11月26日星期六,它仍然只打印 WEEKDAY。它不起作用,我被卡住了:/
I'm trying to make it compare what day of the week it is and if it is a weekend then perform an action(not implemented yet) but if I put in today's date 25/11/2016 or tomorrows which is a Saturday 26/11/2016, it still only prints "WEEKDAY". Its not working and I'm stuck :/
public static void calcDatePrice(String a, boolean b, double c){
System.out.println("CALC PRICE METHOD: " + a);
Double price;
Date d1 = new Date(a);
Calendar c1 = Calendar.getInstance();
c1.setTime(d1);
System.out.println(c1.get(Calendar.DAY_OF_WEEK));
if ((c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
|| (Calendar.DAY_OF_WEEK == Calendar.SUNDAY)) { //or sunday
System.out.println("WEEKEND PRICE");
}else {
System.out.println("WEEKDAY");
}
}
推荐答案
在您的if语句在星期天忘记了c1.get。应该是这样的:
In your if statement you forgot the c1.get on sunday. Should be like this:
if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
c1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
为什么还要发送布尔b和双c?它从未使用过。
Also why do you send in the boolean b and double c? It's never used.
这篇关于确定日期是工作日/周末java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文