Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda Time: How to get dates of weekdays on some date interval?

I have two LocalDates that represent some time interval. Now i have to get LocalDates of all fridays, that this interval contains. Easiest way to do it?

like image 947
Koguro Avatar asked Dec 04 '25 09:12

Koguro


1 Answers

package org.life.java.so.questions;

import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;

/**
 *
 * @author Jigar
 */
public class JodaTimeDateTraverseQuestion {
    public static void main(String[] args) {

        DateTime startDt = new DateTime(2010,12,1,0,0,0,0);//1st Dec 2010
        DateTime endDt = new DateTime(2010,12,31,0,0,0,0);//31st Dec 2010
        DateTime tempDate = new DateTime(startDt.getMillis());
        while(tempDate.compareTo(endDt) <=0 ){
            if(tempDate.getDayOfWeek() !=  DateTimeConstants.SATURDAY && tempDate.getDayOfWeek() !=  DateTimeConstants.SUNDAY){
                System.out.println(""+tempDate);
            }
            tempDate = tempDate.plusDays(1);

        }


    }
}
like image 64
jmj Avatar answered Dec 05 '25 22:12

jmj