|
@@ -1,6 +1,7 @@
|
|
package com.mixsmart.utils;
|
|
package com.mixsmart.utils;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.*;
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.HashUtil;
|
|
import cn.hutool.core.util.HashUtil;
|
|
import cn.hutool.core.util.NumberUtil;
|
|
import cn.hutool.core.util.NumberUtil;
|
|
@@ -1037,24 +1038,27 @@ public class CustomFunction {
|
|
**/
|
|
**/
|
|
public static Object dateAfter(Object date ,Object n){
|
|
public static Object dateAfter(Object date ,Object n){
|
|
if(StringUtils.isNotEmpty(date)&&StringUtils.isNumber(n)){
|
|
if(StringUtils.isNotEmpty(date)&&StringUtils.isNumber(n)){
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
|
- Date d= parseDate(date.toString());
|
|
|
|
- if(d!=null){
|
|
|
|
- cal.setTime(d);
|
|
|
|
- cal.add(Calendar.DATE,StringUtils.handObj2Integer(n));
|
|
|
|
-// if(date.toString().contains("-")){
|
|
|
|
-// return dateToStr(cal.getTime(),"yyyy-MM-dd");
|
|
|
|
-// } if(date.toString().contains("年")){
|
|
|
|
-// return dateToStr(cal.getTime(),"yyyy年MM月dd日");
|
|
|
|
-// }else{
|
|
|
|
-// return dateToStr(cal.getTime(),"yyyy.MM.dd");
|
|
|
|
-// }
|
|
|
|
- return cal.getTime();
|
|
|
|
- }
|
|
|
|
|
|
+ DateTime dt = new DateTime(date.toString());
|
|
|
|
+ dt.offset(DateField.HOUR_OF_DAY,24*Integer.parseInt(n.toString()));
|
|
|
|
+ return dt.toString(DatePattern.UTC_PATTERN);
|
|
}
|
|
}
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+// System.out.println(dateAfter("2020-01-25T16:00:00.000Z",-1));
|
|
|
|
+ DateTime dt2=new DateTime("2022-10-15T13:30:00.000Z");
|
|
|
|
+ DateTime dt=new DateTime("2022-10-13T8:30:00.000Z");
|
|
|
|
+ System.out.println(HashUtil.identityHashCode(dt));
|
|
|
|
+ System.out.println(HashUtil.identityHashCode(dt2));
|
|
|
|
+// System.out.println(DateUtil.between(dt,dt2, DateUnit.HOUR));
|
|
|
|
+ System.out.println(hoursPassed(dt,dt2));
|
|
|
|
+ System.out.println(minutesPassed(dt,dt2));
|
|
|
|
+ System.out.println(daysPassed(dt,dt2));
|
|
|
|
+ System.out.println(conversionUnit(181,"m"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
public static String dateToStr(Date date, String formatter) {
|
|
public static String dateToStr(Date date, String formatter) {
|
|
String value = null;
|
|
String value = null;
|
|
if(null != date) {
|
|
if(null != date) {
|
|
@@ -1189,7 +1193,16 @@ public class CustomFunction {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Description
|
|
|
|
+ * @Param [data , unit 输入单位]
|
|
|
|
+ * @return java.lang.Object
|
|
|
|
+ * @Author yangyj
|
|
|
|
+ * @Date 2022.10.13 14:13
|
|
|
|
+ **/
|
|
public static Object conversionUnit(Object data,Object unit){
|
|
public static Object conversionUnit(Object data,Object unit){
|
|
|
|
+
|
|
if(StringUtils.isNumber(data)&&StringUtils.isNotEmpty(unit)){
|
|
if(StringUtils.isNumber(data)&&StringUtils.isNotEmpty(unit)){
|
|
//统一转化成毫秒在处理
|
|
//统一转化成毫秒在处理
|
|
long ms=0;
|
|
long ms=0;
|
|
@@ -1277,6 +1290,9 @@ public class CustomFunction {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static Object daysPassed(Object t1,Object t2){
|
|
|
|
+ return timePassed(t1,t2,"D",0,"yyyy-MM-dd");
|
|
|
|
+ }
|
|
public static Object hoursPassed(Object t1,Object t2){
|
|
public static Object hoursPassed(Object t1,Object t2){
|
|
return timePassed(t1,t2,"H",0,"yyyy-MM-dd HH");
|
|
return timePassed(t1,t2,"H",0,"yyyy-MM-dd HH");
|
|
}
|
|
}
|
|
@@ -1399,17 +1415,17 @@ public class CustomFunction {
|
|
**/
|
|
**/
|
|
public static Object timePassed(Object t1,Object t2,Object mode,Object scale,Object format){
|
|
public static Object timePassed(Object t1,Object t2,Object mode,Object scale,Object format){
|
|
if(t1!=null&&t2!=null&&StringUtils.isNotEmpty(mode)&&StringUtils.isNotEmpty(scale)&&StringUtils.isNotEmpty(format)){
|
|
if(t1!=null&&t2!=null&&StringUtils.isNotEmpty(mode)&&StringUtils.isNotEmpty(scale)&&StringUtils.isNotEmpty(format)){
|
|
- Date d1 = parseDate(t1,handleNull(format));
|
|
|
|
- Date d2 = parseDate(t2,handleNull(format));
|
|
|
|
- assert d2 != null;
|
|
|
|
- assert d1 != null;
|
|
|
|
- if(d1.after(d2)&&StringUtils.isEquals("H",mode)){
|
|
|
|
- /*假如是计算相差单位是小时,当开始时间大于结束时间,需要考虑跨年的情况*/
|
|
|
|
- Calendar c =Calendar.getInstance();
|
|
|
|
- c.setTime(d1);
|
|
|
|
- c.add(Calendar.YEAR, -1);
|
|
|
|
- d1=c.getTime();
|
|
|
|
- }
|
|
|
|
|
|
+// Date d1 = parseDate(t1,handleNull(format));
|
|
|
|
+// Date d2 = parseDate(t2,handleNull(format));
|
|
|
|
+ DateTime d1 = new DateTime(t1.toString());
|
|
|
|
+ DateTime d2 = new DateTime(t2.toString());
|
|
|
|
+// if(d1.after(d2)&&StringUtils.isEquals("H",mode)){
|
|
|
|
+// /*假如是计算相差单位是小时,当开始时间大于结束时间,需要考虑跨年的情况*/
|
|
|
|
+// Calendar c =Calendar.getInstance();
|
|
|
|
+// c.setTime(d1);
|
|
|
|
+// c.add(Calendar.YEAR, -1);
|
|
|
|
+// d1=new DateTime(c.getTime());
|
|
|
|
+// }
|
|
long range = d2.getTime()-d1.getTime();
|
|
long range = d2.getTime()-d1.getTime();
|
|
long r=0;
|
|
long r=0;
|
|
if(StringUtils.isEquals("Y",mode.toString())){
|
|
if(StringUtils.isEquals("Y",mode.toString())){
|