| | |
| | | dateInfo.setSecond(second);
|
| | | return dateInfo;
|
| | | }
|
| | | |
| | | public static String dateDiff4(Date startTime, Date endTime) throws Exception {
|
| | |
|
| | | String datatime = "0分";
|
| | |
|
| | | long nm = 1000 * 60;// 一分钟的毫秒数
|
| | | long nh = 1000 * 60 * 60;// 一小时的毫秒数
|
| | | long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
|
| | |
|
| | | // 获得两个时间的毫秒时间差异
|
| | | long diff = endTime.getTime() - startTime.getTime();
|
| | | long day = diff / nd;// 计算差多少天
|
| | | long hour = diff % nd / nh;// 计算差多少小时
|
| | | long min = diff % nd % nh / nm;// 计算差多少分钟
|
| | |
|
| | | if (day > 0) {
|
| | | datatime = day + "天";
|
| | | } else {
|
| | | if (hour > 0) {
|
| | | datatime = hour + "时";
|
| | | } else {
|
| | | if (min < 0)
|
| | | min = 0;
|
| | | datatime = min + "分";
|
| | | }
|
| | | }
|
| | | return datatime;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过时间秒毫秒数判断两个时间的间隔
|
| | |
| | | int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
|
| | | return Math.abs(month + result);
|
| | | }
|
| | | |
| | |
|
| | | public static Date getTodayStartTime() {
|
| | | Calendar todayStart = Calendar.getInstance();
|
| | | todayStart.set(Calendar.HOUR_OF_DAY,0);
|
| | | todayStart.set(Calendar.MINUTE,0);
|
| | | todayStart.set(Calendar.SECOND,0);
|
| | | todayStart.set(Calendar.MILLISECOND,0);
|
| | | return todayStart.getTime();
|
| | | }
|
| | | |
| | | public static Date getTodayEndTime() {
|
| | | Calendar todayEnd = Calendar.getInstance();
|
| | | todayEnd.set(Calendar.HOUR_OF_DAY,23);
|
| | | todayEnd.set(Calendar.MINUTE,59);
|
| | | todayEnd.set(Calendar.SECOND,59);
|
| | | todayEnd.set(Calendar.MILLISECOND,999);
|
| | | return todayEnd.getTime();
|
| | | }
|
| | | |
| | |
|
| | | public static void main(String[] args) throws ParseException {
|
| | | System.out.println(getMonthSpace("2012-02", "2012-02"));
|