java取的3月第二个周日

来源:互联网 发布:好看的小说知乎 编辑:程序博客网 时间:2024/05/16 09:42
Calendar cal2 = Calendar.getInstance();
/*设置时间为3月第二个礼拜天*/
cal2.set(Calendar.MONTH, 2);
cal2.set(Calendar.DAY_OF_MONTH, 1);

cal2.set(Calendar.DAY_OF_MONTH, getSecondSunDayDate(cal2.get(Calendar.DAY_OF_WEEK)));


public static int getSecondSunDayDate(int firstDayOfMonthByWeek){
switch (firstDayOfMonthByWeek){
case 1: 
return 8;
case 2: 
return 14;
case 3: 
return 13;
case 4: 
return 12;
case 5: 
return 11;
case 6: 
return 10;
case 7: 
return 9;
}
return -1;
}

原创粉丝点击