两个日期之间的差异天数错误?

时间:2015-12-01 10:36:27

标签: android

这是我的旧帖子的扩展帖子,目前还无法解决: android diff days between two dates

我想知道2个日期之间的差异天数。 为此我使用此代码:

                DatePicker datepicker= (DatePicker) findViewById(R.id.datepicker);

                Log.e("-->",""+datepicker.getMonth());
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.YEAR, datepicker.getYear());
                calendar.set(Calendar.MONTH, datepicker.getMonth());
                calendar.set(Calendar.DATE, datepicker.getDayOfMonth());
                calendar.set(Calendar.HOUR, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                long dpDate = calendar.getTimeInMillis();


                Calendar Today = Calendar.getInstance();
                Today.set(Calendar.YEAR, Today.get(Calendar.YEAR));
                Today.set(Calendar.MONTH, Today.get(Calendar.MONTH));
                Today.set(Calendar.DATE, Today.get(Calendar.DATE));
                Today.set(Calendar.HOUR_OF_DAY, 0);
                Today.set(Calendar.MINUTE, 0);
                Today.set(Calendar.SECOND, 0);
                Date date = Today.getTime();


                Log.e("-->", "cal1: " + calendar.getTime());
                Log.e("-->", "cal2: " + Today.getTime());


                long diff = calendar.getTimeInMillis() - Today.getTimeInMillis();
                long days = diff / (24 * 60 * 60 * 1000);

                Log.e("-->", "days: " + days);
                Log.e("-->", "====================");

这是我的日志: Can you finde the mistake?

我不明白!

0 个答案:

没有答案