Joda Time, Get week days [duplicate]

徘徊边缘 提交于 2020-01-01 09:47:22

问题


How to make the local date count only week date?

For example

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

I am look for a way to remove the weekends?


回答1:


Use the getDayOfWeek() method. Return will be as follows. Inorder to get only week days.. you just need to check whether the return value is less than or equal to 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;



回答2:


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++;
        }

    }


来源:https://stackoverflow.com/questions/15338196/joda-time-get-week-days

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!