计算一个月后是星期几,计算星期几,public stati
分享于 点击 6126 次 点评:250
计算一个月后是星期几,计算星期几,public stati
public static int getWeekByDate(Date date){ Calendar aCalendar = Calendar.getInstance(); aCalendar.setTime(date); int x = aCalendar.get(Calendar.DAY_OF_WEEK); int y = 0; if(x == 1){ y = 7; }else if(x == 2){ y = 1; }else if(x == 3){ y = 2; }else if(x == 4){ y = 3; }else if(x == 5){ y = 4; }else if(x == 6){ y = 5; }else if(x == 7){ y = 6; }else{ y = -1; } return y; } public static Date getNextMonthDate(Calendar calendar){ //当前月份 int currentMonth = calendar.get(Calendar.MONTH); //设置为下一个月 calendar.set(Calendar.MONTH,currentMonth+1); //获取下个月的时间 Date date = calendar.getTime(); return date; } public static void main(String[] args) { //当前时间 Calendar calendar = Calendar.getInstance(); Date date = getNextMonthDate(calendar); //获取当天的星期 int s = getWeekByDate(date); System.out.println(s); }//该片段来自于http://byrx.net
用户点评