Apache Commons-lang3
long millisecondslefttoday = 86400000- dateutils.getfragmentinmilliseconds (Calendar.getinstance ( ), calendar.date);
System.currenttimemillis () is a timestamp of 0 time zones, so you have to add 8 hours.
The most basic wording:
Public classMain { Public Static voidMain (string[] args) {Longhour = 60 * 60 * 1000; LongTime =System.currenttimemillis (); System.out.println (time); time+ = 8 *hour; System.out.println (time); time%= 24 *hour; System.out.printf ("%02d:%02d\n", Time/hour, time% hour/60000); time= * hour-Time ; System.out.printf ("%02d:%02d\n", Time/hour, time% hour/60000); }}
In the current time zone has daylight saving time, another one with System.currenttimemillis () the answer is not handled correctly, such as 15 U.S. daylight savings date from March 8 2 o'clock in the morning, if it is March 8 1 o'clock, that way calculated is wrong, The calendar API can be handled correctly, although it is difficult to use.
Calendar C = calendar.getinstance (); long now =10000); long Millis = C.gettimeinmillis ()-now;
The wording in Java8
LocalTime midnight == = = Todaymidnight.plusdays (1); System.out.println (TimeUnit.NANOSECONDS.toSeconds (Duration.between (Localdatetime.now (), tomorrowmidnight). Tonanos ()));
https://www.zhihu.com/question/28475461
Java system time, how to calculate how much time is left from now to the wee hours?