. , .
NB: : , , , , 01/01/2015. .
private boolean checkSameDate(Calendar cal1, Calendar cal2) {
if ((cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR))
&& (cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR))) {
return true;
}
return false;
}
private void checkDate(Date date) {
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
Calendar cal2 = new GregorianCalendar();
cal2.setTime(date);
cal.add(Calendar.DAY_OF_YEAR, 1);
if (checkSameDate(cal, cal2)) {
} else {
cal.add(Calendar.DAY_OF_YEAR, -2);
if (checkSameDate(cal, cal2)) {
} else {
DateFormat sdf = new SimpleDateFormat("dd MMMM - HH:mm");
System.out.println(sdf.format(date));
}
}
}
Edit
, , 31/12/-1, 01/01/. , : , 24
SimpleDateFormat, https://ideone.com/dsxKN9, , .
2
I just see what you want today , not tomorrow :). To blame! I will try to fix it, but if you understand the logic, you can do it.
source
share