fork download
  1. import java.time.LocalDateTime;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.Locale;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. String defaultSimpleDateFormatPattern = "MMM dd, uuuu HH:mm:ss";
  10. ZoneId tzNY = ZoneId.of("America/New_York");
  11. ZoneId tzLos = ZoneId.of("America/Los_Angeles");
  12. String dateToTest = "Jan 03, 2015 23:59:59";
  13.  
  14. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(defaultSimpleDateFormatPattern, Locale.ENGLISH);
  15. LocalDateTime ldt = LocalDateTime.parse(dateToTest, dtf);
  16.  
  17. ZonedDateTime zdtNY = ldt.atZone(tzNY);
  18. ZonedDateTime zdtLos = ldt.atZone(tzLos);
  19.  
  20. System.out.println(zdtNY.isAfter(zdtLos) ? "after" : zdtNY.isBefore(zdtLos) ? "before" : "equal");
  21. }
  22. }
Success #stdin #stdout 0.18s 53204KB
stdin
Standard input is empty
stdout
before