So I have this piece of code that would return the current EST
Date easternTime = new Date();
DateFormat format = new SimpleDateFormat("h:mm a");
format.setTimeZone(TimeZone.getTimeZone("EST"));
return format.format(easternTime);
let say it return x = 12:15PM
I want to compare x to 3:00PM EST to see if x before or after 3:00PM EST, and/or is x between 3:00PM – 6:00PM EST. Is there a way to do this.
We dont have to use java.util.date. I take solution with calendar as well
I would definitely do this in Joda Time instead. If you really want to do this with the built-in API, you need to use
Calendarto find the local time in a particular time zone – but Joda would make it much simpler.You’d use a
DateTimewhich is in a specific time zone, and possibly take theLocalTimefrom that to compare with someLocalTimes you’ve hard-coded (or read from a configuration file etc).