Authored by kun

删除冗余代码

@@ -10,8 +10,7 @@ import org.apache.commons.lang3.StringUtils; @@ -10,8 +10,7 @@ import org.apache.commons.lang3.StringUtils;
10 10
11 import java.text.ParseException; 11 import java.text.ParseException;
12 import java.text.SimpleDateFormat; 12 import java.text.SimpleDateFormat;
13 -import java.time.LocalDate;  
14 -import java.time.LocalDateTime; 13 +import java.time.*;
15 import java.time.format.DateTimeFormatter; 14 import java.time.format.DateTimeFormatter;
16 import java.util.Calendar; 15 import java.util.Calendar;
17 import java.util.Date; 16 import java.util.Date;
@@ -175,31 +174,6 @@ public final class DateUtil { @@ -175,31 +174,6 @@ public final class DateUtil {
175 } 174 }
176 } 175 }
177 176
178 - public static Integer getTimeSeconds(String timeStr) {  
179 - String afterTime = "";  
180 - timeStr = timeStr.trim();  
181 - String[] hengStrs = timeStr.split("-");  
182 - String[] maoStrs = timeStr.split(":");  
183 - if(hengStrs.length == 2) {  
184 - afterTime = timeStr + "-01 00:00:00";  
185 - } else if(hengStrs.length == 3 && maoStrs.length == 1) {  
186 - afterTime = timeStr + " 00:00:00";  
187 - } else if(hengStrs.length == 3 && maoStrs.length == 3) {  
188 - afterTime = timeStr;  
189 - }  
190 -  
191 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
192 - Date date = null;  
193 -  
194 - try {  
195 - date = sdf.parse(afterTime);  
196 - long e = date.getTime();  
197 - return Integer.valueOf((int)(e / 1000L));  
198 - } catch (ParseException var8) {  
199 - return null;  
200 - }  
201 - }  
202 -  
203 /** 177 /**
204 * 获取当前时间,格式yyyy-MM-dd HH:mm:ss 178 * 获取当前时间,格式yyyy-MM-dd HH:mm:ss
205 * @return 179 * @return
@@ -217,15 +191,17 @@ public final class DateUtil { @@ -217,15 +191,17 @@ public final class DateUtil {
217 } 191 }
218 192
219 public static int getHour(Date date) { 193 public static int getHour(Date date) {
220 - Calendar calendar = Calendar.getInstance();  
221 - calendar.setTime(date);  
222 - return calendar.get(11); 194 + Instant instant = date.toInstant();
  195 + ZoneId zoneId = ZoneId.systemDefault();
  196 + LocalTime localTime = instant.atZone(zoneId).toLocalTime();
  197 + return localTime.getHour();
223 } 198 }
224 199
225 - public static int getMinute(Date date) {  
226 - Calendar calendar = Calendar.getInstance();  
227 - calendar.setTime(date);  
228 - return calendar.get(12); 200 + public static int getMinute1(Date date) {
  201 + Instant instant = date.toInstant();
  202 + ZoneId zoneId = ZoneId.systemDefault();
  203 + LocalTime localTime = instant.atZone(zoneId).toLocalTime();
  204 + return localTime.getMinute();
229 } 205 }
230 206
231 public static int getAddOrMinusDay(Date date, int num) { 207 public static int getAddOrMinusDay(Date date, int num) {
@@ -237,63 +213,10 @@ public final class DateUtil { @@ -237,63 +213,10 @@ public final class DateUtil {
237 } 213 }
238 214
239 public static Date getAddOrMinusDay2(Date date, int num) { 215 public static Date getAddOrMinusDay2(Date date, int num) {
240 - GregorianCalendar gc = (GregorianCalendar)Calendar.getInstance();  
241 - gc.setTime(date);  
242 - gc.add(5, num);  
243 - return gc.getTime(); 216 + Instant instant = date.toInstant();
  217 + ZoneId zoneId = ZoneId.systemDefault();
  218 + LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime().plusDays(num);
  219 + ZonedDateTime zdt = localDateTime.atZone(zoneId);
  220 + return Date.from(zdt.toInstant());
244 } 221 }
245 -  
246 - public static int getMonthStart() {  
247 - Calendar cal = Calendar.getInstance();  
248 - int month = cal.get(2) + 1;  
249 - int year = cal.get(1);  
250 - return getTimeSeconds(year + "-" + month).intValue();  
251 - }  
252 -  
253 - public static int getMonthEnd() {  
254 - Calendar cal = Calendar.getInstance();  
255 - cal.set(5, cal.getMaximum(5));  
256 - int month = cal.get(2) + 1;  
257 - int year = cal.get(1);  
258 - int day = cal.get(5);  
259 - if(month + 1 == 13) {  
260 - month = 1;  
261 - ++year;  
262 - }  
263 -  
264 - Integer time = Integer.valueOf(getTimeSeconds(year + "-" + month + "-" + day).intValue() + 86400);  
265 - return time.intValue();  
266 - }  
267 -  
268 - public static boolean isValidDate(String s, String formats) {  
269 - try {  
270 - SimpleDateFormat e = new SimpleDateFormat(formats);  
271 - e.parse(s);  
272 - return true;  
273 - } catch (Exception var3) {  
274 - return false;  
275 - }  
276 - }  
277 -  
278 - public static String getCronFromDateTime(String datetimeStr, String format) {  
279 - if(StringUtils.isBlank(datetimeStr)) {  
280 - return null;  
281 - } else {  
282 - LocalDateTime localDateTime = LocalDateTime.parse(datetimeStr, DateTimeFormatter.ofPattern(format));  
283 - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");  
284 - return localDateTime.format(formatter);  
285 - }  
286 - }  
287 -  
288 - public static int getWeekInterval(long dateInt) {  
289 - Calendar calendar = Calendar.getInstance();  
290 - int curWeekInt = calendar.get(3);  
291 - int curYearInt = calendar.get(1);  
292 - Calendar calendar1 = Calendar.getInstance();  
293 - calendar1.setTime(new Date(dateInt * 1000L));  
294 - int weekInt = calendar1.get(3);  
295 - int yearInt = calendar1.get(1);  
296 - return curYearInt == yearInt?curWeekInt - weekInt:52 * (curYearInt - yearInt) + curWeekInt - weekInt;  
297 - }  
298 -  
299 } 222 }