8

如何使本地日期仅计算周日期?

例如

LocalDate date = new LocalDate();
date.plusDays(10); //it returns plus days including sat and sun as 2013-03-21
//i am looking for a way
date.plusDays(10); //should return as 2013-03-26

我正在寻找一种方法来消除周末?

4

2 回答 2

23

使用getDayOfWeek()方法。回报如下。为了只得到工作日..你只需要检查返回值是否小于或等于5。

public static final int MONDAY = 1;
public static final int TUESDAY = 2;
public static final int WEDNESDAY = 3;
public static final int THURSDAY = 4;
public static final int FRIDAY = 5;
public static final int SATURDAY = 6;
public static final int SUNDAY = 7;
于 2013-03-11T12:09:42.910 回答
5
LocalDate newDate = new LocalDate();
    int i=0;
    while(i<days)//days == as many as u wanted
    {
        newDate = newDate.plusDays(1);
        System.out.println("new date"+newDate);
        if(newDate.getDayOfWeek()<=5)
        {
            i++;
        }

    }
于 2013-03-11T13:37:00.650 回答