首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

jode-time 取得一个的日历

2012-12-21 
jode-time 获得一个的日历public class JodaTimeTest { public static void main(String[] args){ ListDa

jode-time 获得一个的日历

public class JodaTimeTest {

public static void main(String[] args){
List<DateTime> list = getDateTimesByMonth(DateTime.now());
for(DateTime t :list){
System.out.println("dyaofWeek:"+t.getDayOfWeek());
System.out.println("getBirthMonthText:"+t.toString());
}

}

public static List<DateTime> getDateTimesByMonth(DateTime d){
DateTime temp = new DateTime(d.getYear(),d.getMonthOfYear(),1,0,0);

List<DateTime> list = new ArrayList<DateTime>();
//上月(根据需求进行改变)
int week = temp.getDayOfWeek();
if(week!=7){
for(int i=0;i<week;i++){
list.add(temp.plusDays(-week+i));
}
}
//本月
list.add(temp);
for(int i=1;i<=31;i++){
temp = temp.plusDays(1);
if(temp.getMonthOfYear() != d.getMonthOfYear())break;
list.add(temp);
}
//下月(根据需求进行改变)
if(temp.getDayOfWeek() !=6){
for(int i=0;i<7;i++){
temp = temp.plusDays(1);
if(temp.getDayOfWeek() == 7)break;
list.add(temp);
}
}
return list;
}


}

?

热点排行