1. 程式人生 > >判斷指定月份、日期是否在時間範圍內

判斷指定月份、日期是否在時間範圍內

public boolean isInMonthDay(int month, int day, Calendar minCal, Calendar maxCal){
        boolean res = false;
        if(minCal == null || maxCal == null){
            return res;
        }
        Calendar tarCal = Calendar.getInstance();
        tarCal.set(minCal.get(Calendar.YEAR), month, day);
        if
((tarCal.before(maxCal) || tarCal.equals(maxCal)) && (tarCal.after(minCal) || tarCal.equals(minCal))){ res = true; } if(! res && maxCal.get(Calendar.YEAR) != tarCal.get(Calendar.YEAR)){ tarCal.set(maxCal.get(Calendar.YEAR), month
, day); if((tarCal.before(maxCal) || tarCal.equals(maxCal)) && (tarCal.after(minCal) || tarCal.equals(minCal))){ res = true; } } return res; }