public static TimeSchedule2 getTimeSchedule2(String endTime, int runDays) { TimeSchedule2 timeSchedule = new TimeSchedule2(); SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startTime; startTime = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd"); startTime = startTime + " 00:00:00"; // if(null == startTime) { // // startTime = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd"); // startTime = startTime + " 00:00:00"; // // } // else { // startTime = DateUtil.format(DateUtil.parse(startTime), "yyyy-MM-dd"); // startTime = startTime + " 00:00:00"; // } try { java.util.Date begin = dfs.parse(startTime); java.util.Date end = dfs.parse(endTime); long between = (end.getTime() - begin.getTime()) / 1000; // 除以1000是为了转换成秒 long days = (between / 60) / (24 * 60); long hours = (between / 60) % (24 * 60) / 60; long minutes = (between / 60) % 60; long seconds = between - days * (24 * 60 * 60) - hours * (60 * 60) - minutes * 60; timeSchedule.setDates(runDays); timeSchedule.setHour(hours); timeSchedule.setMinute(minutes); timeSchedule.setSecond(seconds); } catch (ParseException e) { e.printStackTrace(); } return timeSchedule; }
public static String getLastTimeText2(TimeSchedule2 timeSchedule) { String lastTimeText = ""; if (timeSchedule.getDates() > 0) { lastTimeText = lastTimeText + timeSchedule.getDates() + "天"; } if (timeSchedule.getHour() < 10) { lastTimeText = lastTimeText + "0" + timeSchedule.getHour() + "小时"; } else { lastTimeText = lastTimeText + timeSchedule.getHour() + "小时"; } if (timeSchedule.getMinute() < 10) { lastTimeText = lastTimeText + "0" + timeSchedule.getMinute() + "分钟"; } else { lastTimeText = lastTimeText + timeSchedule.getMinute() + "分钟"; } return lastTimeText; }