fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. String input = "07:11" ;
  16. String[] parts = input.split( ":" );
  17. System.out.println( Arrays.toString( parts ) );
  18.  
  19. // Better approach: Let `LocalTime` do all the work.
  20. LocalTime localTime = LocalTime.parse( input );
  21. LocalTime start = LocalTime.of( 5 , 0 ); // 5 AM = 05:00.
  22. LocalTime stop = LocalTime.of( 22 , 0 ); // 10 PM = 22:00.
  23.  
  24. Boolean isBetween =
  25. ( ! localTime.isBefore( start ) )
  26. &&
  27. localTime.isBefore( stop )
  28. ;
  29. System.out.println( "Is " + localTime + " between " + start + " and " + stop + ": " + isBetween );
  30.  
  31. }
  32. }
Success #stdin #stdout 0.14s 4386816KB
stdin
Standard input is empty
stdout
[07, 11]
Is 07:11 between 05:00 and 22:00: true