This commit is contained in:
xiangwbs
2018-04-22 11:14:43 +08:00
parent 1f1ffa55eb
commit 3ce980758b
2 changed files with 14 additions and 12 deletions
@@ -14,7 +14,8 @@ import java.util.*;
*/
public class DateUtil {
private static DecimalFormat df = new DecimalFormat("######0.00");
public static final long SECOND = 1000;
public static final long MILLIS = 1;
public static final long SECOND = MILLIS * 1000;
public static final long MINUTE = SECOND * 60;
public static final long HOUR = MINUTE * 60;
public static final long DAY = 24 * HOUR;
@@ -230,10 +231,10 @@ public class DateUtil {
*/
public static Map<String, Integer> getDatePoorHour(Date startDate, Date endDate) {
long diff = startDate.getTime() - endDate.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);
long diffSeconds = diff / SECOND % 60;
long diffMinutes = diff / MINUTE % 60;
long diffHours = diff / HOUR % 24;
long diffDays = diff / DAY;
Map<String, Integer> map = new HashMap<>();
map.put("days", (int) diffDays);
map.put("hours", (int) diffHours);
@@ -16,7 +16,7 @@ import java.util.*;
* 说明: 日期处理类
*/
public class DateUtil2 {
public static final long SECOND = 1000;
public static final long SECOND = 1;
public static final long MINUTE = SECOND * 60;
public static final long HOUR = MINUTE * 60;
public static final long DAY = HOUR * 24;
@@ -292,7 +292,7 @@ public class DateUtil2 {
* 遍历获取两个日期之间天数集合
*
* @param startDate yyyy-MM-dd
* @param endDate yyyy-MM-dd
* @param endDate yyyy-MM-dd
* @return
*/
public static List<String> listDate(String startDate, String endDate) {
@@ -401,7 +401,7 @@ public class DateUtil2 {
LocalDateTime sDateTime = LocalDateTime.parse(startDateTime, getDateFormat(YYYY_MM_DD_HH_MM_SS));
LocalDateTime eDateTime = LocalDateTime.parse(endDateTime, getDateFormat(YYYY_MM_DD_HH_MM_SS));
Duration duration = Duration.between(sDateTime, eDateTime);
long diff = duration.toMillis();
long diff = duration.getSeconds();
long diffSeconds = diff / SECOND % 60;
long diffMinutes = diff / MINUTE % 60;
long diffHours = diff / HOUR % 24;
@@ -414,6 +414,11 @@ public class DateUtil2 {
return map;
}
public static void main(String[] args) {
Map<String, Integer> dateTimePool = getDateTimePool("2018-11-11 00:00:00", "2018-11-11 01:30:00");
System.out.println(dateTimePool);
}
/**
* 获取两个时间差(时间分量:年月日)
*
@@ -443,10 +448,6 @@ public class DateUtil2 {
return list;
}
public static void main(String[] args) {
boolean b = compareDate("2017-10-10", "2017-10-11", "2017-10-11", "2017-10-12");
System.out.println(b);
}
/**
* 判断两者时间是否重合 重合返回true
*