fork download
  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.Locale;
  5. import java.util.TimeZone;
  6.  
  7. public class Main {
  8. public static void main(String[] args) throws ParseException {
  9. String defaultSimpleDateFormatPattern = "MMM dd, yyyy HH:mm:ss";
  10. TimeZone tzNY = TimeZone.getTimeZone("America/New_York");
  11. TimeZone tzLos = TimeZone.getTimeZone("America/Los_Angeles");
  12. String dateToTest = "Jan 03, 2015 23:59:59";
  13. SimpleDateFormat df = new SimpleDateFormat(defaultSimpleDateFormatPattern, Locale.ENGLISH);
  14.  
  15. df.setTimeZone(tzNY);
  16. Calendar c = Calendar.getInstance();
  17. c.setTime(df.parse(dateToTest));
  18.  
  19. df.setTimeZone(tzLos);
  20. Calendar c1 = Calendar.getInstance(tzNY);
  21. c1.setTime(df.parse(dateToTest));
  22.  
  23. System.out.println(c.after(c1) ? "after" : (c.before(c1) ? "before" : "equal"));
  24. }
  25. }
Success #stdin #stdout 0.17s 56620KB
stdin
Standard input is empty
stdout
before