Skip to content

Instantly share code, notes, and snippets.

@MenoData
Last active June 17, 2017 15:27
Show Gist options
  • Save MenoData/90bcd254fafda19b15b578130b0b59fe to your computer and use it in GitHub Desktop.
Save MenoData/90bcd254fafda19b15b578130b0b59fe to your computer and use it in GitHub Desktop.
Getting the duration between a time of a day and midnight at the end of same day
import net.time4j.*;
import net.time4j.format.expert.*;
public class UntilMidnight {
public static void main(String... args) throws ParseException {
PlainTime t = Iso8601Format.EXTENDED_WALL_TIME.parse("12:03:00");
Duration<ClockUnit> duration =
Duration.inClockUnits().between(t, PlainTime.midnightAtEndOfDay()); // until 24:00
Duration.Formatter<ClockUnit> f = Duration.formatter(ClockUnit.class, "hh:mm:ss");
System.out.println(f.format(duration)); // 11:57:00
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment