Example usage for java.time LocalTime until

List of usage examples for java.time LocalTime until

Introduction

In this page you can find the example usage for java.time LocalTime until.

Prototype

@Override
public long until(Temporal endExclusive, TemporalUnit unit) 

Source Link

Document

Calculates the amount of time until another time in terms of the specified unit.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    long s = l.until(LocalTime.NOON, ChronoUnit.HOURS);
    System.out.println(s);//from ww  w.jav a  2s .  c o m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2014, Month.JANUARY, 7);
    LocalDate ld2 = LocalDate.of(2014, Month.MAY, 18);

    LocalTime lt1 = LocalTime.of(7, 0);
    LocalTime lt2 = LocalTime.of(9, 30);

    long days = ld1.until(ld2, ChronoUnit.DAYS);
    System.out.println(days);// w  w  w  .  ja  va  2  s .c om
    long hours = lt1.until(lt2, ChronoUnit.HOURS);
    System.out.println(hours);
    long minutes = lt1.until(lt2, ChronoUnit.MINUTES);
    System.out.println(minutes);
}

From source file:metrolink.MetrolinkCalculator.java

public long getNextArrivalTime(List<StopTime> stopTimes, String time) {
    LocalTime[] timeArray = new LocalTime[stopTimes.size()];
    for (int i = 0; i < stopTimes.size(); i++) {
        timeArray[i] = convertTime(stopTimes.get(i).getArrivalTime());
    }/*from www.jav a2 s  .  c o  m*/
    Arrays.sort(timeArray);
    LocalTime convertedTime = convertTime(time);
    LocalTime timeResult = null;
    for (LocalTime currentTime : timeArray) {
        //            System.out.println( currentTime );
        if (currentTime.compareTo(convertedTime) >= 0) {
            timeResult = currentTime;
            break;
        }
    }
    if (timeResult == null) {
        timeResult = timeArray[0];
    }
    long difference = convertedTime.until(timeResult, ChronoUnit.MINUTES);
    if (difference < 0) {
        difference += ONEDAYINMINUTES;
    }
    return difference;
}