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