Created
June 22, 2016 07:46
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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