Maybe a person just doesn’t know how to get the time difference between two detectors in different time intervals (days, hours ...)
If the old version is java 7 and lower, then use jodatime . There are many methods for calculating the date and time. So for example you can count how many days before the event.
Date event = ...; Date now = ...; // перейти в jodatime LocalDate localEvent = new LocalDate(event); LocalDate localNow = new LocalDate(now); Days days = Days.daysBetween(localNow, localEvent); int d = days.getDays(); // сколько дней до события
Directly tracing from the official FAQ
There are also methods for calculating the number of hours, minutes, etc.
if (d == -1) { System.out.println("Вчера"); } else if (d == 1) { System.out.println("Завтра"); } else if (d == 2) { System.out.println("Послезавтра"); } else if (d > 0) { System.out.printf("Через %d дня\n", d); } else if (d == 0) { // подсчитать часы. только потребуется перевод в LocalDateTime или LocalTime }
The new java 8 seems to have borrowed a lot from jodatime.
Here's another thing. LocalData from jodatime takes into account the timezone and new LocalDate (date) may differ from the date (+ | - day). Then you can use the method LocalDate.fromDateFields (Date date)
LocalDate local = LocalDate.fromDateFields(date)
Then timezone is ignored, local will show the exact same day as date.