Calendar cal1 = getCalendarFromDate(mStartDate);
                long startTime = cal1.getTimeInMillis();
                Calendar cal2 = getCalendarFromDate(Untils.getdata(mEndDate);
                long endTime = cal2.getTimeInMillis();
                int numberOfDays = (int) (endTime - startTime) / (24 * 60 * 60 * 1000);


    private Calendar getCalendarFromDate(final String date) {
        int year = 0;
        int month = 0;
        int day = 0;
        try {
            String[] array = date.split("-");
            int[] arrayInt = new int[array.length];
            for (int i = 0; i < array.length; i++) {
                arrayInt[i] = Integer.parseInt(array[i]);
                if (i == 0) {
                    year = arrayInt[0];
                } else if (i == 1) {
                    month = arrayInt[1];
                } else if (i == 2) {
                    day = arrayInt[2];
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        if (year > 0 && month >= 0 && day >= 0) {
            cal.set(year, month, day);
        }
        return cal;
    }

 

posted on 2016-05-21 10:35  0代码狂人0  阅读(1226)  评论(0编辑  收藏  举报