在Java中如何输入任何一个年份的,打印出全年的星期日 在Java中如何输入任何一个年份的,打印出全年的星期日 例如: 输入2012 打印出2012年所以的星期天的日期 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void getAllSunday(int year){ Calendar c = Calendar.getInstance(); c.set(year,0,1);//设置传入年的1月1号 int first = c.get(Calendar.DAY_OF_WEEK); for(int i = 0;i < 7;i++){//找到全年第一个星期日 if(first == 1){ System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日"); c.add(Calendar.DAY_OF_MONTH,7); break; }else{ c.add(Calendar.DAY_OF_MONTH,1); } } Calendar end = Calendar.getInstance(); end.set(year + 1, 0, 1); while(c.before(end)){//循环,加7,直到年底 System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日"); c.add(Calendar.DAY_OF_YEAR, 7); } }找到全年第一个星期日,然后就一直加7吧,打印对应的日期 public void getAllSunday(int year){ Calendar c = Calendar.getInstance(); c.set(year,0,1);//设置传入年的1月1号 int first = c.get(Calendar.DAY_OF_WEEK); for(int i = 0;i < 7;i++){//找到全年第一个星期日 if(first == 1){ System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日"); c.add(Calendar.DAY_OF_MONTH,7); break; }else{ c.add(Calendar.DAY_OF_MONTH,1); } } Calendar end = Calendar.getInstance(); end.set(year + 1, 0, 1); while(c.before(end)){//循环,加7,直到年底 System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日"); c.add(Calendar.DAY_OF_YEAR, 7); } }找到全年第一个星期日,然后就一直加7吧,打印对应的日期 ANT远程删除问题 struts2中文件下载MIME类型问题 使用复合主键,还是增加一个唯一标识的单列主键? FORM表单提交到ActionForm的中文变乱码,求助 struts 如何把从数据库查出来的数据保存在本地 hql返回结果集的问题 菜鸟求助!Bad version in .class files Oracle小问题 找不到struts.jar的问题! 大地jsp免费空间上传系统已经完善 在Java中如何输入任何一个年份的,打印出全年的星期日 菜鸟求问Struts的配置问题
Calendar c = Calendar.getInstance();
c.set(year,0,1);//设置传入年的1月1号
int first = c.get(Calendar.DAY_OF_WEEK);
for(int i = 0;i < 7;i++){//找到全年第一个星期日
if(first == 1){
System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
c.add(Calendar.DAY_OF_MONTH,7);
break;
}else{
c.add(Calendar.DAY_OF_MONTH,1);
}
}
Calendar end = Calendar.getInstance();
end.set(year + 1, 0, 1);
while(c.before(end)){//循环,加7,直到年底
System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
c.add(Calendar.DAY_OF_YEAR, 7);
}
}
找到全年第一个星期日,然后就一直加7吧,打印对应的日期
Calendar c = Calendar.getInstance();
c.set(year,0,1);//设置传入年的1月1号
int first = c.get(Calendar.DAY_OF_WEEK);
for(int i = 0;i < 7;i++){//找到全年第一个星期日
if(first == 1){
System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
c.add(Calendar.DAY_OF_MONTH,7);
break;
}else{
c.add(Calendar.DAY_OF_MONTH,1);
}
}
Calendar end = Calendar.getInstance();
end.set(year + 1, 0, 1);
while(c.before(end)){//循环,加7,直到年底
System.out.println(c.get(Calendar.MONDAY) + 1 + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
c.add(Calendar.DAY_OF_YEAR, 7);
}
}
找到全年第一个星期日,然后就一直加7吧,打印对应的日期