gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:53 25 4
gpt4 key购买 nike

我有两个代表某个时间间隔的 LocalDates。现在我必须获取此间隔包含的所有星期五的 LocalDates。最简单的方法?

最佳答案

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);

}


}
}

关于java - Joda Time : How to get dates of weekdays on some date interval?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4547768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com