package com.vci.rmip.code.client.codeapply.Apply410.utils; // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import org.apache.commons.lang.StringUtils; public class VciDateUtil { private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; public static final String DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; public static final String DateTimeFormatStr = "yyyyMMddHHmmss"; public static final String DateTimeMillFormatStr = "yyyyMMddHHmmssSSS"; public static final String DateTimeMillFormat = "yyyy-MM-dd HH:mm:ss.SSS"; public static final String DateFormat = "yyyy-MM-dd"; public static final String TimeFormat = "HH:mm:ss"; private VciDateUtil() { } public static Date str2Date(String str, String format) throws Exception { if (null != str && !"".equals(str) && !str.equals("null")) { if (null == format || "".equals(format) || format.equals("null")) { format = "yyyy-MM-dd HH:mm:ss.SSS"; } SimpleDateFormat sdf = new SimpleDateFormat(format); Date date = null; try { date = sdf.parse(str); return date; } catch (ParseException var5) { throw new Exception(var5); } } else { return null; } } public static Date getCurrentMonday() { return getCurrentWeekDay(2); } public static Date getCurrentWeekDay(int dayOfWeek) { if (dayOfWeek > 7) { dayOfWeek = 7; } if (dayOfWeek < 1) { dayOfWeek = 1; } Date date = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(7, dayOfWeek); calendar.set(11, 0); calendar.set(12, 0); calendar.set(13, 0); calendar.set(14, 0); return calendar.getTime(); } public static Date getCurrentFriday() { return getCurrentWeekDay(6); } public static String date2Str(Date date, String format) { if (null == date) { return null; } else { if (format == null || format.trim().length() == 0) { format = "yyyy-MM-dd HH:mm:ss.SSS"; } SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } } public static String timestamp2Str(Timestamp time) { Date date = null; if (null == time) { return null; } else { if (null != time) { date = new Date(time.getTime()); } return date2Str(date, "yyyy-MM-dd HH:mm:ss.SSS"); } } public static Timestamp str2Timestamp(String str) throws Exception { if (str != null && str.trim().length() != 0) { Date date = str2Date(str, "yyyy-MM-dd HH:mm:ss.SSS"); return new Timestamp(date.getTime()); } else { return null; } } public static String compareDate(String date, String date1) throws Exception { if (date != null && date.trim().length() != 0 && date1 != null && date1.trim().length() != 0) { try { long time = str2Date(date, "yyyy-MM-dd").getTime(); long time1 = str2Date(date1, "yyyy-MM-dd").getTime(); if (time == time1) { return "="; } else if (time < time1) { return "<"; } else { return time > time1 ? ">" : ""; } } catch (Exception var6) { throw var6; } } else { throw new Exception("传入compareDate的参数为空"); } } public static String compareDate(Date date, Date date1) { if (date != null && date1 != null) { long time = date.getTime(); long time1 = date1.getTime(); if (time == time1) { return "="; } else if (time < time1) { return "<"; } else { return time > time1 ? ">" : ""; } } else { return ""; } } public static String dateTimeAddMinutes(String date, int minute) throws Exception { String ret = ""; if (date == null || date.equals("")) { date = date2Str(getNow(), "yyyy-MM-dd HH:mm:ss.SSS"); } if (minute == 0) { return date; } else { Date d = str2Date(date, "yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(12, minute); return date2Str(cal.getTime(), "yyyy-MM-dd HH:mm:ss"); } } public static Date getDateAddDay(String date, int dayCount) throws Exception { if (date != null && !date.equals("") && !date.equals("null")) { if (dayCount == 0) { return str2Date(date, "yyyy-MM-dd"); } else { Date d = str2Date(date, "yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(5, dayCount); return cal.getTime(); } } else { return getNow(); } } public static Date getDateAddDay(Date date, int dayCount) { if (dayCount == 0) { return date; } else { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(5, dayCount); return cal.getTime(); } } public static long getDaySub(String beginDateStr, String endDateStr) { if (beginDateStr != null && !beginDateStr.trim().equals("") && endDateStr != null && !endDateStr.trim().equals("")) { long day = 0L; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { Date beginDate = format.parse(beginDateStr); Date endDate = format.parse(endDateStr); day = (endDate.getTime() - beginDate.getTime()) / 86400000L; } catch (ParseException var8) { var8.printStackTrace(); } return day; } else { return 0L; } } public static long getDaySub(Date date, Date date1) { return (date.getTime() - date1.getTime()) / 86400000L; } public static Date addOrSubDate(Date d, int addDayType, int addCount) { Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(addDayType, addCount); return cal.getTime(); } public static Date getNow() { return new Date(); } public static String getNowString() { return getNowString("yyyy-MM-dd HH:mm:ss.SSS"); } public static String getNowString(String simpleDateFormat) { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat(simpleDateFormat); return formatter.format(currentTime); } public static Date getNow(String simpleDateFormat) throws Exception { return str2Date(getNowString(simpleDateFormat), simpleDateFormat); } public static String getCountdown(String oldtime, String newTime) { if (oldtime != null && !oldtime.trim().equals("") && newTime != null && !newTime.equals("")) { try { Date date1 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(oldtime); Date date2 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(newTime); long l = date1.getTime() - date2.getTime() > 0L ? date1.getTime() - date2.getTime() : date2.getTime() - date1.getTime(); long d = 0L; long yushu = l; long h = 0L; long m = 0L; if (l > 86400000L) { yushu = l % 86400000L; d = (l - yushu) / 86400000L; } if (yushu > 3600000L) { h = (yushu - yushu % 3600000L) / 3600000L; yushu %= 3600000L; } if (yushu > 60000L) { m = (yushu - yushu % 60000L) / 60000L; } return date1.getTime() - date2.getTime() < 0L ? "已经超期" + d + "天" + h + "小时" + m + "分" : "还剩下" + d + "天" + h + "小时" + m + "分"; } catch (Exception var14) { return ""; } } else { return ""; } } public static long getDateDiffer(String oldTime, String newTime) { if (oldTime != null && !oldTime.trim().equals("") && newTime != null && !newTime.equals("")) { try { Date date1 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(oldTime); Date date2 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(newTime); return date1.getTime() - date2.getTime(); } catch (Exception var4) { return 0L; } } else { return 0L; } } public static int getWeeks(int year) { if (year == 0) { return year; } else { //int week = false; int days = 365; if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) { days = 366; } int week = days / 7; return week; } } public static int getWeekOnDate(Date date) { GregorianCalendar g = new GregorianCalendar(); g.setTime(date); return isSunday(date) ? g.get(3) - 1 : g.get(3); } public static Calendar getCalendarFromWeek(String year, int week) throws Exception { Date newDate = str2Date(year + "-01-01", "yyyy-MM-dd"); Calendar caleNew = Calendar.getInstance(); caleNew.setTime(newDate); caleNew.add(3, week - 1); return caleNew; } public static String[] getDaysInWeek(int year, int week) { String[] thisWeek = new String[7]; try { GregorianCalendar gc = (GregorianCalendar)getCalendarFromWeek(year + "-01-01", week); for(int i = 0; i < 7; ++i) { Calendar myCale = Calendar.getInstance(); myCale.setTime(gc.getTime()); myCale.set(5, gc.get(5) - gc.get(7) + i + 2); thisWeek[i] = date2Str(myCale.getTime(), "yyyy-MM-dd"); } } catch (Exception var6) { System.out.println(var6.getMessage()); } return thisWeek; } public static boolean isSunday() { return isSunday(new Date()); } public static boolean isSunday(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int week = calendar.get(7) - 1; return week == 0; } public static boolean isWeekend(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int week = calendar.get(7) - 1; return week == 0 || week == 1; } public static boolean isFriday(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int week = calendar.get(7) - 1; return week == 5; } public static boolean isMouthEnd(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int dayOfMonth = calendar.get(5); int endMonth = calendar.getActualMaximum(5); return endMonth == dayOfMonth; } public static boolean isSeasonEnd(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int y = calendar.get(2) + 1; int d = calendar.get(5); if (y == 3 && d == 31) { return true; } else if (y == 6 && d == 30) { return true; } else if (y == 9 && d == 30) { return true; } else { return y == 12 && d == 31; } } public static boolean isYearEnd(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int y = calendar.get(2) + 1; int d = calendar.get(5); return y == 12 && d == 31; } public static Long getProcessedTime(Date newDate, Date startDate) { try { Long p = newDate.getTime() - startDate.getTime(); return p; } catch (Exception var3) { return 0L; } } public static String getProcessedTime(Date startDate) { return getProcessedTime(new Date(), startDate) + "ms"; } public static String getCurrentYear() { Calendar c = Calendar.getInstance(); return String.valueOf(c.get(1) + 1900); } public static String getCurrentYearStart() { return getCurrentYear() + "-01-01 00:00:00"; } public static String getCurrentYearEnd() { return getCurrentYear() + "-12-31 23:59:59"; } public static String getCurrentQuarter() { String currentMouth = getCurrentMouth(); int currentMouthInt = getInt(currentMouth); if (currentMouthInt > 0 && currentMouthInt <= 3) { return "1"; } else if (currentMouthInt > 3 && currentMouthInt <= 6) { return "2"; } else { return currentMouthInt > 6 && currentMouthInt <= 9 ? "3" : "4"; } } private static int getInt(String s) { try { return Integer.valueOf(s); } catch (Exception var2) { return 0; } } public static String getCurrentQuarterStart() { String currentQuarter = getCurrentQuarter(); if ("1".equalsIgnoreCase(currentQuarter)) { return getCurrentYearStart(); } else if ("2".equalsIgnoreCase(currentQuarter)) { return getCurrentYear() + "-04-01 00:00:00"; } else { return "3".equalsIgnoreCase(currentQuarter) ? getCurrentYear() + "-07-01 00:00:00" : getCurrentYear() + "-10-01 00:00:00"; } } public static String getCurrentQuarterEnd() { String currentQuarter = getCurrentQuarter(); if ("1".equalsIgnoreCase(currentQuarter)) { return getCurrentYear() + "-03-31 23:59:59"; } else if ("2".equalsIgnoreCase(currentQuarter)) { return getCurrentYear() + "-06-30 23:59:59"; } else { return "3".equalsIgnoreCase(currentQuarter) ? getCurrentYear() + "-09-30 23:59:59" : getCurrentYear() + "-12-31 23:59:59"; } } public static String getCurrentMouth() { Calendar cal = Calendar.getInstance(); cal.setTime(getNow()); int m = cal.get(2); return m < 10 ? "0" + String.valueOf(m) : String.valueOf(m); } public static String getCurrentMouthStart() { String currentMouth = getCurrentMouth(); return getCurrentYear() + "-" + currentMouth + "-01 00:00:00"; } public static String getCurrentMouthEnd() { String currentMouth = getCurrentMouth(); int currentMouthInt = getInt(currentMouth); if (currentMouthInt != 1 && currentMouthInt != 3 && currentMouthInt != 5 && currentMouthInt != 7 && currentMouthInt != 8 && currentMouthInt != 10 && currentMouthInt != 12) { if (currentMouthInt == 2) { return isLeapYear(getInt(getCurrentYear())) ? getCurrentYear() + "-" + currentMouth + "-29 23:59:59" : getCurrentYear() + "-" + currentMouth + "-28 23:59:59"; } else { return getCurrentYear() + "-" + currentMouth + "-30 23:59:59"; } } else { return getCurrentYear() + "-" + currentMouth + "-31 23:59:59"; } } public static boolean isLeapYear(int year) { return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; } public static String getCurrentDay() { Calendar cal = Calendar.getInstance(); cal.setTime(getNow()); int day = cal.get(5); return day < 10 ? "0" + String.valueOf(day) : String.valueOf(day); } /*public static String getCurrentDayStart() { return LocalDateTimeUtil.of(LocalDateTimeUtil.now().toLocalDate(), LocalTime.MIN).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); } public static String getCurrentDayEnd() { return LocalDateTime.of(LocalDateTime.now().toLocalDate(), LocalTime.MAX).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); }*/ public static List getDateInRange(Date dBegin, Date dEnd) { List lDate = new ArrayList(); lDate.add(dBegin); Calendar calBegin = Calendar.getInstance(); calBegin.setTime(dBegin); Calendar calEnd = Calendar.getInstance(); calEnd.setTime(dEnd); while(dEnd.after(calBegin.getTime())) { calBegin.add(5, 1); lDate.add(calBegin.getTime()); } return lDate; } public static Date getDateFromStringForVci(String value) { Date d = null; if (StringUtils.isNotBlank(value)) { try { if (value.indexOf("-") > -1 && value.indexOf(".") > -1 && value.indexOf(" ") > -1 && value.substring(value.lastIndexOf(".") + 1).length() >= 9) { String ymd = value.substring(0, value.indexOf(".")); value = value.substring(value.indexOf(".") + 1); if (value.indexOf(".") > -1) { String hms = value.substring(0, value.lastIndexOf(".")); String nano = value.substring(value.lastIndexOf(".") + 1).trim(); if (nano.length() > 3) { nano = nano.substring(0, 3); } hms = hms.replace(".", ":").replace(" ", ""); Date tempDate = str2Date(ymd + " " + hms, "yyyy-M-d h:m:s"); if (tempDate != null) { d = str2Date(date2Str(tempDate, "yyyy-MM-dd HH:mm:ss") + "." + nano, "yyyy-MM-dd HH:mm:ss.SSS"); } } } else if (VciBaseUtil.isNumber(value)) { d = new Date(); try { d = str2Date(value, "yyyyMMddHHmmssSSS"); } catch (Exception var8) { if (value.length() != 14) { d.setTime(VciBaseUtil.getLong(value)); } else { try { d = str2Date(value, "yyyyMMddHHmmss"); Calendar cal = Calendar.getInstance(); cal.setTime(d); if (cal.get(1) < 1900) { d.setTime(VciBaseUtil.getLong(value)); } } catch (Exception var7) { d.setTime(VciBaseUtil.getLong(value)); } } } } else { d = str2Date(value, "yyyy-MM-dd HH:mm:ss.SSS"); } } catch (Exception var9) { try { d = str2Date(value, "yyyy-MM-dd HH:mm:ss.SSS"); } catch (Exception var6) { } } } return d; } public static Date readText2Date(String text) { if (VciBaseUtil.isNullOrNullString(text)) { return null; } else { SimpleDateFormat dateFormat = null; int exactDateLength = 0; if (text.trim().indexOf("/") > -1 && text.trim().length() == 19) { exactDateLength = 19; dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); } else if (text.trim().indexOf("/") > -1 && text.trim().length() == 17) { exactDateLength = 17; dateFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss"); } else if (text.trim().indexOf("/") > -1 && text.trim().length() == 8) { exactDateLength = 8; dateFormat = new SimpleDateFormat("yy/MM/dd"); } else if (text.trim().indexOf("-") > -1 && text.trim().length() >= 19) { if (text.trim().length() == 19) { exactDateLength = 19; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } else if (text.trim().length() == 23) { exactDateLength = 23; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); } } else if (text.trim().indexOf("-") > -1 && text.trim().length() == 17) { exactDateLength = 17; dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); } else if (text.trim().indexOf("-") > -1 && text.trim().length() == 8) { exactDateLength = 8; dateFormat = new SimpleDateFormat("yy-MM-dd"); } else { exactDateLength = 19; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } if (text != null && exactDateLength >= 0 && text.length() != exactDateLength) { throw new IllegalArgumentException("不能初始化时间,因为内容不到" + exactDateLength + "长度"); } else { try { return str2Date(date2Str(dateFormat.parse(text), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss.SSS"); } catch (ParseException var4) { throw new IllegalArgumentException("不能格式化日期: " + var4.getMessage(), var4); } catch (Exception var5) { throw new IllegalArgumentException("不能格式化日期: " + var5.getMessage(), var5); } } } } public static String getChinaDate(String d) throws Exception { Date s = str2Date(d, "yyyy-MM-dd"); SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); Calendar today = Calendar.getInstance(); try { today.setTime(chineseDateFormat.parse(date2Str(s, "yyyy年MM月dd日"))); } catch (ParseException var5) { throw new Exception(var5); } Lunar lunar = new Lunar(today); return lunar.getDate(); } }