package com.qianwen.smartman.modules.tpm.utils;
|
|
import java.text.SimpleDateFormat;
|
import java.time.Instant;
|
import java.time.LocalDateTime;
|
import java.time.ZoneId;
|
import java.util.Calendar;
|
import java.util.Date;
|
import com.qianwen.smartman.common.constant.DateConstant;
|
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/tpm/utils/DateUtils.class */
|
public class DateUtils {
|
public static Date stringToDate(String time) throws Exception {
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateConstant.PATTERN_DATE);
|
Date date = simpleDateFormat.parse(time);
|
return date;
|
}
|
|
public static String getStringDate(Date time) {
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateConstant.PATTERN_DATE);
|
String date = simpleDateFormat.format(time);
|
return date;
|
}
|
|
public static boolean isToday(String time) throws Exception {
|
SimpleDateFormat fmt = new SimpleDateFormat(DateConstant.PATTERN_DATE);
|
Date date = fmt.parse(time);
|
if (fmt.format(date).toString().equals(fmt.format(new Date()).toString())) {
|
return true;
|
}
|
return false;
|
}
|
|
public static String dateToString(Date time) {
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
|
return fmt.format(time);
|
}
|
|
public static long getDaySub(String beginDateStr, String endDateStr) {
|
long day = 0;
|
SimpleDateFormat format = new SimpleDateFormat(DateConstant.PATTERN_DATE);
|
try {
|
Date beginDate = format.parse(beginDateStr);
|
Date endDate = format.parse(endDateStr);
|
day = (endDate.getTime() - beginDate.getTime()) / 86400000;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return day;
|
}
|
|
public static Date plusDay(Date data, int num) {
|
new Date();
|
new SimpleDateFormat(DateConstant.PATTERN_DATE_TIME);
|
Calendar ca = Calendar.getInstance();
|
ca.setTime(data);
|
ca.add(5, num);
|
Date currdate = ca.getTime();
|
return currdate;
|
}
|
|
public static LocalDateTime dateToLocalDateTime(Date date) {
|
Instant instant = date.toInstant();
|
ZoneId zone = ZoneId.systemDefault();
|
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
|
return localDateTime;
|
}
|
|
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
|
Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
return date;
|
}
|
}
|