mport Org.apache.commons.lang.time.DateUtils;ImportOrg.joda.time.DateTime;Importorg.joda.time.Duration;Importorg.junit.Test;ImportJava.time.LocalDateTime;ImportJava.time.temporal.ChronoUnit;ImportJava.util.Calendar;/*** Created by Administrator on 2016/12/12.*/ Public classtimetest {@Test Public voidGetTime () {//Method One LongMillisecondslefttoday = 86400000-dateutils.getfragmentinmilliseconds (Calendar.getinstance (), calendar.date); LongSecondslefttoday = 86400-dateutils.getfragmentinseconds (Calendar.getinstance (), calendar.date); System.out.println ("The remaining milliseconds of the Day 1:" +millisecondslefttoday); System.out.println ("Remaining seconds of the Day 1:" +secondslefttoday); //Method Twodatetime datetime =NewDateTime (). Millisofday (). Withmaximumvalue (); LongMILLSECONDS2 =NewDuration (Newdatetime (), datetime). Getmillis (); LongCount =NewDuration (Newdatetime (), datetime). Getstandardseconds (); System.out.println ("The remaining milliseconds of the Day 2:" +millSeconds2); System.out.println ("Remaining seconds of the Day 2:" +count); //method Three: LocalDateTime and chronounit for 1.8 newLocalDateTime midnight = Localdatetime.now (). Plusdays (1). Withhour (0). Withminute (0). Withsecond (0). Withnano (0); LongMillseconds =ChronoUnit.MILLIS.between (Localdatetime.now (), midnight); Longseconds =ChronoUnit.SECONDS.between (Localdatetime.now (), midnight); System.out.println ("The remaining milliseconds of the day 3:" +millseconds); System.out.println ("Remaining seconds of the day 3:" +seconds); }}
Java time operation: Get the remaining time of the day