Authored by kun

删除冗余代码

... ... @@ -10,8 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
... ... @@ -175,31 +174,6 @@ public final class DateUtil {
}
}
public static Integer getTimeSeconds(String timeStr) {
String afterTime = "";
timeStr = timeStr.trim();
String[] hengStrs = timeStr.split("-");
String[] maoStrs = timeStr.split(":");
if(hengStrs.length == 2) {
afterTime = timeStr + "-01 00:00:00";
} else if(hengStrs.length == 3 && maoStrs.length == 1) {
afterTime = timeStr + " 00:00:00";
} else if(hengStrs.length == 3 && maoStrs.length == 3) {
afterTime = timeStr;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(afterTime);
long e = date.getTime();
return Integer.valueOf((int)(e / 1000L));
} catch (ParseException var8) {
return null;
}
}
/**
* 获取当前时间,格式yyyy-MM-dd HH:mm:ss
* @return
... ... @@ -217,15 +191,17 @@ public final class DateUtil {
}
public static int getHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(11);
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalTime localTime = instant.atZone(zoneId).toLocalTime();
return localTime.getHour();
}
public static int getMinute(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(12);
public static int getMinute1(Date date) {
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalTime localTime = instant.atZone(zoneId).toLocalTime();
return localTime.getMinute();
}
public static int getAddOrMinusDay(Date date, int num) {
... ... @@ -237,63 +213,10 @@ public final class DateUtil {
}
public static Date getAddOrMinusDay2(Date date, int num) {
GregorianCalendar gc = (GregorianCalendar)Calendar.getInstance();
gc.setTime(date);
gc.add(5, num);
return gc.getTime();
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime().plusDays(num);
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
public static int getMonthStart() {
Calendar cal = Calendar.getInstance();
int month = cal.get(2) + 1;
int year = cal.get(1);
return getTimeSeconds(year + "-" + month).intValue();
}
public static int getMonthEnd() {
Calendar cal = Calendar.getInstance();
cal.set(5, cal.getMaximum(5));
int month = cal.get(2) + 1;
int year = cal.get(1);
int day = cal.get(5);
if(month + 1 == 13) {
month = 1;
++year;
}
Integer time = Integer.valueOf(getTimeSeconds(year + "-" + month + "-" + day).intValue() + 86400);
return time.intValue();
}
public static boolean isValidDate(String s, String formats) {
try {
SimpleDateFormat e = new SimpleDateFormat(formats);
e.parse(s);
return true;
} catch (Exception var3) {
return false;
}
}
public static String getCronFromDateTime(String datetimeStr, String format) {
if(StringUtils.isBlank(datetimeStr)) {
return null;
} else {
LocalDateTime localDateTime = LocalDateTime.parse(datetimeStr, DateTimeFormatter.ofPattern(format));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
return localDateTime.format(formatter);
}
}
public static int getWeekInterval(long dateInt) {
Calendar calendar = Calendar.getInstance();
int curWeekInt = calendar.get(3);
int curYearInt = calendar.get(1);
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(new Date(dateInt * 1000L));
int weekInt = calendar1.get(3);
int yearInt = calendar1.get(1);
return curYearInt == yearInt?curWeekInt - weekInt:52 * (curYearInt - yearInt) + curWeekInt - weekInt;
}
}
... ...