|
|
|
@ -9,6 +9,7 @@ import cn.hutool.core.lang.Range;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
|
|
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
@ -31,8 +32,8 @@ public class MyDateUtils extends DateUtil {
|
|
|
|
|
|
|
|
|
|
public static String[] parsePatterns = {
|
|
|
|
|
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy年MM月dd日",
|
|
|
|
|
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "HH时mm分", "HH:mm","HH:mm:ss",
|
|
|
|
|
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM","yyyyMMdd"};
|
|
|
|
|
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "HH时mm分", "HH:mm", "HH:mm:ss",
|
|
|
|
|
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM", "yyyyMMdd"};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前Date型日期
|
|
|
|
@ -116,6 +117,7 @@ public class MyDateUtils extends DateUtil {
|
|
|
|
|
}
|
|
|
|
|
return format(str, "HH:mm");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日期型转化为"MM/dd" 格式
|
|
|
|
|
*/
|
|
|
|
@ -125,6 +127,7 @@ public class MyDateUtils extends DateUtil {
|
|
|
|
|
}
|
|
|
|
|
return format(str, "MM/dd");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取服务器启动时间
|
|
|
|
|
*/
|
|
|
|
@ -132,12 +135,14 @@ public class MyDateUtils extends DateUtil {
|
|
|
|
|
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
|
|
|
|
return new Date(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日期型转化为"yyyy-MM-dd HH:mm" 格式
|
|
|
|
|
*/
|
|
|
|
|
public static String formatYmdHmTime(Date date) {
|
|
|
|
|
return null == date ? null : DatePattern.NORM_DATETIME_MINUTE_FORMAT.format(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算两个时间差
|
|
|
|
|
*/
|
|
|
|
@ -159,10 +164,23 @@ public class MyDateUtils extends DateUtil {
|
|
|
|
|
return day + "天" + hour + "小时" + min + "分钟";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public static String dfdsa(Date start, Date end, DateField unit, int step, boolean isIncludeStart, boolean isIncludeEnd){
|
|
|
|
|
// new Range(DateUtil.date(start), DateUtil.date(end), (current, end1, index) -> {
|
|
|
|
|
// DateTime dt = DateUtil.date(start).offsetNew(unit, (index + 1) * step);
|
|
|
|
|
// return dt.isAfter(end1) ? null : dt;
|
|
|
|
|
// }, isIncludeStart, isIncludeEnd);
|
|
|
|
|
// }
|
|
|
|
|
/**
|
|
|
|
|
* 13位时间戳转10位时间戳
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static BigInteger TimeMillSecond2Second(DateTime dateTime) {
|
|
|
|
|
BigInteger l = BigInteger.valueOf(Math.floorDiv(dateTime.getTime(), 1000l));
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 10位时间戳转13位时间戳
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static BigInteger TimeSecond2MillSecond(long time) {
|
|
|
|
|
BigInteger l = BigInteger.valueOf(time * 1000l);
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|