Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

compare two times in java

String startTime = "10:00";
    String endTime = "12:00";
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    Date d1 = sdf.parse(startTime);
    Date d2 = sdf.parse(endTime);
    long elapsed = d2.getTime() - d1.getTime(); 
    System.out.println(elapsed);
Comment

compare time in java

for ( Map.Entry<DayOfWeek , LocalTime> entry : dayToTimeMap.entrySet () ) {
    DayOfWeek key = entry.getKey ();
    LocalTime value = entry.getValue ();
    int comparison = key.compareTo ( today );
    if ( comparison < 0 ) { // if earlier day…
        earlier.add ( key );
    } else if ( comparison == 0 ) { //If same day…
        if ( value.isBefore ( now ) ) {
            earlier.add ( key );
        } else {  // Else same time as now or later than now…
            later.add ( key );
        }
    } else if ( comparison > 0 ) {
        later.add ( key );
    } else {
        throw new RuntimeException ( "Unexpectedly reached IF-ELSE for comparison: " + comparison );
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Add delay to code in Android 
Java :: strictfp java 
Java :: measure running time of a statement java 
Java :: c# or java 
Java :: java quick sort 
Java :: tic tac toe in java 
Java :: how to add element to end of array java 
Java :: random boolean java 
Java :: spring boot base url 
Java :: resize image icon to fit jlabel 
Java :: how to remove null values collections 
Java :: retrofit android 
Java :: android kill other app programmatically by package 
Java :: java enum length 
Java :: java string to double comma 
Java :: java localtime 
Java :: Java NoClassDefFoundError but class is there 
Java :: java scan a file 
Java :: java insert at index 
Java :: java how to define a function 
Java :: java protected private public 
Java :: simple function java 
Java :: java regex case insensitive 
Java :: java is list ordered 
Java :: java read a line of input 
Java :: jsonArray to list in java 
Java :: display two dimension array java 
Java :: how to make a dictionary in java 
Java :: download File java from website 
Java :: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.5.0:repackage failed: 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =