Last active
June 17, 2017 15:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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