我正在运行以下代码6/7/2018
,以便从返回的任何日期中省略周末。但是,代码似乎将以下几天确定为周末。
13/7/2018 - Friday & 14/7/2018 - Saturday
而不是
14/7/2018 - Saturday & 15/7/2018 - Sunday
我正在更新指示的字段以增加/减少我想选择的未来天数。
如果我输入 5 天返回的日期是12/7/2018
,如果我输入 6 天返回的日期是15/7/2018
.
有什么明显的我遗漏的东西,任何帮助将不胜感激。
Date date=new Date();
Calendar calendar = Calendar.getInstance();
date=calendar.getTime();
SimpleDateFormat s;
s=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(s.format(date));
int days = 5; //I am updating this value to increase and decrease days
for(int i=0;i<days;)
{
calendar.add(Calendar.DAY_OF_MONTH, 1);
//here even sat and sun are added
//but at the end it goes to the correct week day.
//because i is only increased if it is week day
if(calendar.get(Calendar.DAY_OF_WEEK)<=5)
{
i++;
}
}
date=calendar.getTime();
s=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(s.format(date));