1.java8环境
public static void mainString[] args) {Date currentTime = new Date);//从一个 Instant和区域ID获得 LocalDateTime实例LocalDateTime localDateTime=LocalDateTime.ofInstantcurrentTime.toInstant), ZoneId.systemDefault));//获取第第二天零点时刻的实例LocalDateTime toromorrowTime=LocalDateTime.ofInstantcurrentTime.toInstant), ZoneId.systemDefault)).plusDays1).withHour0).withMinute0).withSecond0).withNano0);//ChronoUnit日期枚举类,between方法计算两个时间对象之间的时间量long seconds = ChronoUnit.SECONDS.betweenlocalDateTime, toromorrowTime);System.out.printlnseconds);}
2.
public static void mainString[] args) {long totalTime = 0;try {SimpleDateFormat simpleDateFormat = new SimpleDateFormat"yyyyMMddHHmmss");String currentTime = simpleDateFormat.formatnew Date));String substring = currentTime.substring0, 8)+"235959";long nowTime = simpleDateFormat.parsecurrentTime).getTime))/1000;long endTime = simpleDateFormat.parsesubstring).getTime))/1000;totalTime = endTime - nowTime;
// int hour = int)Math.floortotalTime / 3600));int minute = int)Math.floortotalTime - hour*3600)/60));int second = int)Math.floortotalTime - hour*3600 - minute*60);} catch ParseException e) {logger.info"获取时间差异常");e.printStackTrace);}System.out.printlntotalTime);}