fork download
  1. import java.time.Instant;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.temporal.ChronoUnit;
  5. import java.util.Date;
  6. import java.util.GregorianCalendar;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. ZoneId tz = ZoneId.of("Australia/Brisbane");
  11.  
  12. // A sample java.util.Date representing the local date and time values in Australia/Brisbane
  13. Date dateObj = GregorianCalendar.from(ZonedDateTime.of(2021, 10, 2, 22, 25, 0, 0, tz)).getTime();
  14.  
  15. // Difference between now in Australia/Brisbane and the given java.util.Date
  16. System.out.println(ChronoUnit.DAYS.between(Instant.now().atZone(tz), dateObj.toInstant().atZone(tz)));
  17. }
  18. }
Success #stdin #stdout 0.21s 55780KB
stdin
Standard input is empty
stdout
98