0

我有两个日历calendarCurrentcalendarReceived如何检查它们是否在同一日期(不要考虑小时、分钟、秒)

SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_PATTER, Locale.US);
String receivedStringDate = "2012-12-01T00:33:24.935Z";
sdf.parse(receivedStringDate, new ParsePosition(0));
calendarCurrent = Calendar.getInstance(Locale.US);
calendarReceived = sdf.getCalendar();
4

3 回答 3

2

检查他们的 YEAR、MONTH 和 DATE 字段是否相同:Calendar.get(int)

于 2012-12-01T11:38:08.940 回答
1

Calendar为这个实现接口编写你自己的比较器Comparator<Calendar>

您还可以使用第三方 API,例如JodaTime

于 2012-12-01T11:43:11.170 回答
0

采用 :

Calendar.YEAR
Calendar.MONTH
Calendar.DAY_OF_MONTH

参考:http ://www.vogella.com/articles/JavaDateTimeAPI/article.html

于 2012-12-01T11:39:15.793 回答