AndyC1000
asked on
Create if statement with hour and minute in range
Dear all,
I am wanting to create an if statement, i.e. if between 9.30 and 11.00 do something.
I'm getting the hour and minute values from the calendar object.
Now that I'm using half hour data I'm unsure of how to update the if statement to check for hour and minute in range.
Thanks
I am wanting to create an if statement, i.e. if between 9.30 and 11.00 do something.
I'm getting the hour and minute values from the calendar object.
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
Now that I'm using half hour data I'm unsure of how to update the if statement to check for hour and minute in range.
if ((hour >= 9) && (hour <= 11)) {
value = 1;
}
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With all your questions regarding date manipulation, I would seriously recommend looking at a library such as Joda-Time (http://www.joda.org/joda-time/) or moving to Java 8 (you're not already using 8 are you? I think I've asked this previously). It would make all this SO much easier and most importantly LESS chances for bugs.
If using a library (or moving to Java 8) is even a remote possibility, let me know and I can show you just how easy all this can become!
If using a library (or moving to Java 8) is even a remote possibility, let me know and I can show you just how easy all this can become!
ASKER
Open in new window