Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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);

        }


    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...