Skip to content

Instantly share code, notes, and snippets.

@sisodiakaran
Created June 22, 2016 07:46
Show Gist options
  • Save sisodiakaran/0818545ab263edd991f4abc3f63af35a to your computer and use it in GitHub Desktop.
Save sisodiakaran/0818545ab263edd991f4abc3f63af35a to your computer and use it in GitHub Desktop.
Java method to check whether current time is between start time and end time.
private boolean isTimeBetweenTwoTime(String from, String to) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date date_from = formatter.parse(from);
Date date_to = formatter.parse(to);
Calendar cal = Calendar.getInstance();
String dateNow = formatter.format(cal.getTime());
Date current = formatter.parse(dateNow);
System.out.println(date_from);
System.out.println(date_to);
System.out.println(current);
if (date_from.before(current) && date_to.after(current)) {
System.out.println("Yes time between");
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment