-6

I need to determine if the current time is between 10 and 15 minutes after the hour. So e.g.:

  • if the current time is 9:22 or 14:41, the answer is false
  • if the current time is 1:12 or 18:14, the answer is true

I can't find an example of this anywhere. Does anyone have a general solution?

Mark
  • 1,988
  • 2
  • 24
  • 42
  • 1
    See http://stackoverflow.com/questions/907170/java-getminutes-and-gethours. The question might be different from yours, but you can find your answer there. – exception1 Feb 20 '14 at 20:34
  • OK - so you're saying use JodaTime TimeOfDay.MINUTE_OF_HOUR. Great. – Mark Feb 20 '14 at 20:46
  • BTW, no idea why I have -3 on this?! – Mark Feb 20 '14 at 20:47
  • 1
    You now have -4 on this as you clearly didn't do the expected minimal amount of research - simply searching for some combination of the words "java time minute" should give you a few thousand links which help solve the problem on your own. E.g. [this](https://stackoverflow.com/questions/8150155/java-gethours-getminutes-and-getseconds) is the third result for the exact query `java time minute`. – l4mpi Feb 20 '14 at 20:52
  • @Mark There are even other nice examples in that thread, for example the one from James. It's the same as the answer below. – exception1 Feb 20 '14 at 20:54
  • Did you see where i said "i can't find this"?! I DID search, but didn't find this exact situation/solution. harsh – Mark Mar 18 '14 at 14:01
  • I DID look. The fact that I couldn't find an answer is no reason to vote down ! – Mark Nov 07 '16 at 20:18

3 Answers3

1

Try this:

int min = Calendar.getInstance().get(Calendar.MINUTE);
return min >= 10 && min < 15;
hichris123
  • 10,145
  • 15
  • 56
  • 70
1

The following method should resolve your problem

public boolean isInRange() {
    Calendar calendar = Calendar.getInstance();
    int minute = calendar.get(Calendar.MINUTE);
    return minute >= 10 && minute < 15;
}

It simple recoveries the minute from the current time and verifies if it is between 10 and 15

renke
  • 1,180
  • 2
  • 12
  • 27
0
int minutes = new GregorianCalendar().get(Calendar.MINUTE);
if (minutes >= 10 && minutes <= 15) {
    System.out.println("The time is between 10 and 15 minutes after the current hour.");
}
George Brighton
  • 5,131
  • 9
  • 27
  • 36
elToro
  • 1,003
  • 9
  • 31