List of usage examples for java.time LocalTime until
@Override public long until(Temporal endExclusive, TemporalUnit unit)
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; }