Ver código fonte

代码修改

LAPTOP-KB9HII50\70708 2 anos atrás
pai
commit
ea2163bb84

+ 8 - 13
common/common-util/src/main/java/com/yihu/jw/util/date/DateTimeUtil.java

@ -30,8 +30,7 @@ public class DateTimeUtil {
    public static DateTimeFormatter iso8601Format = DateTimeFormatter.ofPattern(ISO8601Pattern);
    public static String simpleDateTimeFormat(Date date){
        String time = simpleDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
        return time;
        return simpleDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
    }
    public static Date simpleDateTimeParse(String date) throws ParseException {
@ -51,7 +50,7 @@ public class DateTimeUtil {
        return DateUtil.localTimeToDate(localDateTime);
    }
    public static Date iso8601DateTimeParse(String date) throws ParseException {
    public static Date iso8601DateTimeParse(String date){
        if(StringUtils.isEmpty(date)) return null;
        ZonedDateTime zonedDateTime = ZonedDateTime.parse(date,iso8601Format);
@ -61,32 +60,29 @@ public class DateTimeUtil {
    public static String utcDateTimeFormat(Date date){
        //为空判断
        if(date!=null) {
            String time = utcDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
            return time;
            return utcDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
        }
        else{
            return null;
        }
    }
    public static Date utcDateTimeParse(String date) throws ParseException {
    public static Date utcDateTimeParse(String date){
        if(StringUtils.isEmpty(date)) return null;
        return strToDate(date,utcDateTimeFormat);
    }
    public static String slashDateTimeFormat(Date date){
        String result = slashDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
        return result;
        return slashDateTimeFormat.format(DateUtil.dateToLocalDateTime(date));
    }
    public static Date slashDateTimeParse(String date) throws ParseException {
    public static Date slashDateTimeParse(String date){
        return strToDate(date,slashDateTimeFormat);
    }
    public static String simpleDateFormat(Date date){
        String result = simpleDateFormat.format(DateUtil.dateToLocalDateTime(date));
        return result;
        return simpleDateFormat.format(DateUtil.dateToLocalDateTime(date));
    }
    public static Date simpleDateParse(String date) throws ParseException {
@ -96,8 +92,7 @@ public class DateTimeUtil {
    }
    public static String simpleDateTimeShortFormat(Date date){
        String result = simpleDateTimeShortFormat.format(DateUtil.dateToLocalDateTime(date));
        return result;
        return simpleDateTimeShortFormat.format(DateUtil.dateToLocalDateTime(date));
    }
    public static Date simpleDateTimeShortParse(String date) throws ParseException {

+ 51 - 168
common/common-util/src/main/java/com/yihu/jw/util/date/DateUtil.java

@ -186,9 +186,6 @@ public class DateUtil {
    /**
     * 将短时间格式字符串转换为时间
     *
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate, String format) {
        if (StringUtils.isEmpty(strDate)) {
@ -201,9 +198,6 @@ public class DateUtil {
    /**
     * 将短时间格式字符串转换为时间
     *
     * @param strDate
     * @return
     */
    public static Date strToDateTime(String strDate, String format) {
        if (StringUtils.isEmpty(strDate)) {
@ -298,8 +292,6 @@ public class DateUtil {
    /**
     * 获取时间 小时:分;秒 HH:mm:ss
     *
     * @return
     */
    public static String getTimeShort() {
        Date currentTime = new Date();
@ -308,9 +300,6 @@ public class DateUtil {
    /**
     * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static Date strToDateLong(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
@ -322,9 +311,6 @@ public class DateUtil {
    /**
     * 将长时间格式字符串转换为时间 yyyyMMdd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static Date strToYmdDateLong(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
@ -342,9 +328,6 @@ public class DateUtil {
    /**
     * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrLong(Date dateDate) {
        if (dateDate == null) {
@ -355,9 +338,6 @@ public class DateUtil {
    /**
     * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrFormatLong(java.util.Date dateDate) {
        if (dateDate == null) {
@ -373,9 +353,6 @@ public class DateUtil {
    }
    /**
     * 将长时间格式时间转换为字符串 YYYYMMDD
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrFormatShort(java.util.Date dateDate) {
        if (dateDate == null) {
@ -386,9 +363,6 @@ public class DateUtil {
    /**
     * 将长时间格式时间转换为字符串 yyyyMMdd
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrShort(java.util.Date dateDate) {
        if (dateDate == null) {
@ -418,8 +392,6 @@ public class DateUtil {
    /**
     * 得到现在时间
     *
     * @return
     */
    public static Date getNow() {
        Date currentTime = new Date();
@ -428,9 +400,6 @@ public class DateUtil {
    /**
     * 提取一个月中的最后一天
     *
     * @param day
     * @return
     */
    public static Date getLastDate(long day) {
        Date date = new Date();
@ -459,8 +428,6 @@ public class DateUtil {
    /**
     * 得到现在分钟
     *
     * @return
     */
    public static String getTime() {
        Date currentTime = new Date();
@ -472,7 +439,6 @@ public class DateUtil {
     *
     * @param sformat
     *            yyyyMMddhhmmss
     * @return
     */
    public static String getUserDate(String sformat) {
        Date currentTime = new Date();
@ -506,6 +472,7 @@ public class DateUtil {
            LocalDateTime localDateTime = dateToLocalDateTime(date).plusDays(days);
            day = Date.from(localDateTime.atZone(zone).toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return day;
    }
@ -598,7 +565,6 @@ public class DateUtil {
    /**
     * 获取本月第一天
     * @return
     */
    public static String getCurMonthFirstDayShort(){
        return dateFormatter.format(LocalDate.now().withDayOfMonth(1));
@ -607,9 +573,6 @@ public class DateUtil {
    /**
     * 判断是否润年
     *
     * @param ddate
     * @return
     */
    public static boolean isLeapYear(String ddate) {
        /**
@ -622,9 +585,6 @@ public class DateUtil {
    /**
     * 返回美国时间格式 26 Apr 2006
     *
     * @param str
     * @return
     */
    public static String getEDate(String str) {
        Date strtodate = strToDate(str,YYYY_MM_DD);
@ -635,9 +595,6 @@ public class DateUtil {
    /**
     * 获取一个月的最后一天
     *
     * @param dat
     * @return
     */
    public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
        String str = dat.substring(0, 8);
@ -660,8 +617,6 @@ public class DateUtil {
    /**
     * 产生周序列,即得到当前时间所在的年度是第几周
     *
     * @return
     */
    public static String getSeqWeek() {
        LocalDate now = LocalDate.now();
@ -675,43 +630,38 @@ public class DateUtil {
    /**
     * 获得一个日期所在的周的星期几的日期,如要找出2002年2月3日所在周的星期一是几号
     *
     * @param sdate
     * @param num
     * @return
     */
    public static String getWeek(String sdate, String num) {
        // 再转换为时间
        LocalDate localDate = LocalDate.parse(sdate,dateFormatter);
        if (num.equals("1")){ // 返回星期一所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.MONDAY.getValue());
        }
        else if (num.equals("2")){ // 返回星期二所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.TUESDAY.getValue());
        }
        else if (num.equals("3")){ // 返回星期三所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.WEDNESDAY.getValue());
        }
        else if (num.equals("4")){ // 返回星期四所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.THURSDAY.getValue());
        }
        else if (num.equals("5")){ // 返回星期五所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.FRIDAY.getValue());
        }
        else if (num.equals("6")){ // 返回星期六所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.SATURDAY.getValue());
        }
        else if (num.equals("0")){ // 返回星期日所在的日期
            localDate.with(WeekFields.ISO.dayOfWeek(),DayOfWeek.SUNDAY.getValue());
        switch (num) {
            case "1":  // 返回星期一所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.MONDAY.getValue());
                break;
            case "2":  // 返回星期二所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.TUESDAY.getValue());
                break;
            case "3":  // 返回星期三所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.WEDNESDAY.getValue());
                break;
            case "4":  // 返回星期四所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.THURSDAY.getValue());
                break;
            case "5":  // 返回星期五所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.FRIDAY.getValue());
                break;
            case "6":  // 返回星期六所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.SATURDAY.getValue());
                break;
            case "0":  // 返回星期日所在的日期
                localDate.with(WeekFields.ISO.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
                break;
        }
        return dateFormatter.format(localDate);
    }
    /**
     * 根据一个日期,返回是星期几的字符串
     *
     * @param sdate
     * @return
     */
    public static String getWeek(String sdate) {
        // 再转换为时间
@ -722,31 +672,36 @@ public class DateUtil {
    }
    public static String getWeekStr(String sdate) {
        String str = "";
        String str;
        str = getWeek(sdate);
        if ("1".equals(str)) {
            str = "星期日";
        } else if ("2".equals(str)) {
            str = "星期一";
        } else if ("3".equals(str)) {
            str = "星期二";
        } else if ("4".equals(str)) {
            str = "星期三";
        } else if ("5".equals(str)) {
            str = "星期四";
        } else if ("6".equals(str)) {
            str = "星期五";
        } else if ("7".equals(str)) {
            str = "星期六";
        switch (str) {
            case "1":
                str = "星期日";
                break;
            case "2":
                str = "星期一";
                break;
            case "3":
                str = "星期二";
                break;
            case "4":
                str = "星期三";
                break;
            case "5":
                str = "星期四";
                break;
            case "6":
                str = "星期五";
                break;
            case "7":
                str = "星期六";
                break;
        }
        return str;
    }
    /**
     * 日期比较大小
     * @param s1
     * @param s2
     * @return
     */
    public static long compareDate(Date s1, Date s2) {
        try {
@ -759,10 +714,6 @@ public class DateUtil {
    /**
     * 字符串日期比较大小
     * @param format
     * @param s1
     * @param s2
     * @return
     */
    public static long compareDate(String format, String s1, String s2) {
        Date s = strToDate(s1,YYYY_MM_DD);
@ -777,10 +728,6 @@ public class DateUtil {
    /**
     * 两个时间之间的天数
     *
     * @param date1
     * @param date2
     * @return
     */
    public static long getDays(String date1, String date2) {
        if(date1 == null || date1.equals("")){
@ -798,9 +745,6 @@ public class DateUtil {
    /**
     * 返回两个日期相差的天数
     * @param date1
     * @param date2
     * @return
     */
    public static long getDays(Date date1, Date date2) {
        if (date1 == null || date2 == null){
@ -812,9 +756,6 @@ public class DateUtil {
    /**
     * 返回两个日期相差的小时数(保留2位小数)
     * @param date1
     * @param date2
     * @return
     */
    public static float getHours(Date date1, Date date2) {
        if (date1 == null || date2 == null){
@ -830,9 +771,6 @@ public class DateUtil {
    /**
     * 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
     * 此函数返回该日历第一行星期日所在的日期
     *
     * @param sdate
     * @return
     */
    public static String getNowMonth(String sdate) {
        // 取该时间所在月的一号
@ -862,9 +800,6 @@ public class DateUtil {
    /**
     * 返回一个随机数
     *
     * @param i
     * @return
     */
    public static String getRandom(int i) {
        Random jjj = new Random();
@ -898,9 +833,6 @@ public class DateUtil {
    /**
     *  字符串转时间
     * @param str 时间字符串
     * @param eg 格式
     * @return
     */
    public static Date stringToDate(String str, String eg) {
        return strToDate(str,eg);
@ -916,7 +848,6 @@ public class DateUtil {
    /**
     * 获取周一
     * @return
     */
    public static String getMondayOfThisWeek() {
        LocalDate localDate = LocalDate.now().with(WeekFields.ISO.getFirstDayOfWeek());
@ -925,7 +856,6 @@ public class DateUtil {
    /**
     * 获取某个时间的周一
     * @returnc
     */
    public static String getMondayOfThisWeek(Date date) {
        LocalDate localDate = dateToLocalDate(date).with(WeekFields.ISO.getFirstDayOfWeek());
@ -954,9 +884,6 @@ public class DateUtil {
    /**
     * 获取某一时间端内的工作天数
     * @param start
     * @param end
     * @return
     */
    public static long getWorkDays(String start, String end){
        long day = 0;
@ -974,7 +901,6 @@ public class DateUtil {
    /**
     * 获取当月第一天
     * @return
     */
    public static String getFristDayOfMonth() {
        LocalDate localDate = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
@ -998,8 +924,6 @@ public class DateUtil {
    /**
     * 计算预产期
     * 末次月经开始日期(第一天),月份+9,日期+7
     * @param date
     * @return
     */
    public static Date getDueDate(Date date){
        LocalDateTime localDateTime = dateToLocalDateTime(date);
@ -1009,9 +933,6 @@ public class DateUtil {
    /**
     * 计算产检时间
     * @param date
     * @param day
     * @return
     */
    public static Date getPrenatalInspectorDate(Date date,Integer day){
        LocalDateTime localDateTime = dateToLocalDateTime(date);
@ -1021,8 +942,6 @@ public class DateUtil {
    /**
     * 将HH:MM格式的字符串转TIME
     * @param hhmm
     * @return
     */
    public static Time hhmmStrToTime(String hhmm){
        Time time = null;
@ -1038,7 +957,6 @@ public class DateUtil {
    /**
     * 获取当前时间的Timestamp
     * @return
     */
    public static Timestamp getNowTimestamp(){
        Date date = new Date();
@ -1048,9 +966,6 @@ public class DateUtil {
    /**
     *时间字符串转为 时间戳
     * @param str
     * @param format
     * @return
     */
    public static Timestamp toTimestamp(String str, String format) {
@ -1067,9 +982,6 @@ public class DateUtil {
    }
    /**
     *时间字符串转为 时间戳
     * @param str
     * @param
     * @return
     */
    public static Timestamp toTimestamp(String str) {
@ -1091,9 +1003,6 @@ public class DateUtil {
    /**
     *  日期加减天数
     * @param date 时间
     * @param days 天数�?
     * @return
     */
    public static Date setDateTime(Date date,int days){
        LocalDateTime localDateTime = dateToLocalDateTime(date).plusDays(days);
@ -1107,7 +1016,6 @@ public class DateUtil {
    /**
     * 获取去年日期
     * @return
     */
    public static String getLastYear(){
        LocalDateTime localDateTime = LocalDateTime.now().plusYears(-1);
@ -1116,8 +1024,6 @@ public class DateUtil {
    /**
     * 获取儿童的年龄
     * @param date
     * @return
     */
    public static String getChildAge(Date date){
        LocalDate now = LocalDate.now();
@ -1173,7 +1079,6 @@ public class DateUtil {
    /**
     * 获取当月第一天
     * @return
     */
    public static String getFristDayOfMonthThisDate(Date date) {
        LocalDate localDate = dateToLocalDate(date).with(TemporalAdjusters.firstDayOfMonth());
@ -1189,8 +1094,6 @@ public class DateUtil {
    /**
     * 根据日期对象返回星期几
     * @param date
     * @return
     */
    public static int getWeekByDate(Date date){
        LocalDate localDate = dateToLocalDate(date);
@ -1199,7 +1102,6 @@ public class DateUtil {
    /**
     * 获取当天0点
     * @return
     */
    public static Date getDateStart(){
        LocalDate localDate = LocalDate.now();
@ -1210,7 +1112,6 @@ public class DateUtil {
    /**
     * 获取当天23:59:59
     * @return
     */
    public static Date getDateEnd(){
        LocalDate localDate = LocalDate.now();
@ -1222,9 +1123,6 @@ public class DateUtil {
    /**
     * 根据身份证的号码算出当前身份证持有者的年龄
     *
     * @param
     * @throws Exception
     */
    public static int getAgeForIdcard(String idcard) {
        try {
@ -1248,7 +1146,7 @@ public class DateUtil {
            LocalDate localDate = LocalDate.of(year,month,day);
            return localDate.until(LocalDate.now()).getYears();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }
@ -1292,19 +1190,11 @@ public class DateUtil {
    /**
     * 判断时间是否在某个区间内
     * @param time
     * @param begin
     * @param end
     * @return
     */
    public static boolean isInArea(Date time,Date begin,Date end) {
        Long beginTime = compareDateTime(time,begin);
        Long endTime = compareDateTime(time, end);
        if (beginTime > 0 && endTime < 0) {
            return true;
        } else {
            return false;
        }
        return beginTime > 0 && endTime < 0;
    }
    /**
@ -1312,7 +1202,6 @@ public class DateUtil {
     * @param date1 当前时间
     * @param date2 过去时间
     * @param fliter 0不携带秒 1携带秒
     * @return
     */
    public static String getDifferentTimeInfo(Date date1, Date date2,Integer fliter){
        if (date1 == null || date2 == null){
@ -1361,7 +1250,6 @@ public class DateUtil {
     *  返回 两个时间间隔天数/小时数
     * @param date1 当前时间
     * @param date2 过去时间
     * @return
     */
    public static String getDifferentTimeInfo1(Date date1, Date date2){
        if (date1 == null || date2 == null){
@ -1378,7 +1266,7 @@ public class DateUtil {
        long secondFieldDiff = secondsDiff - TimeUnit.MINUTES.toSeconds(minutesDiff);
        if (daysDiff > 0L) {
            result = (String.format("%d天", daysDiff));
            return result.toString();
            return result;
        }
        else if (hourFieldDiff > 0L) {
            result=String.format("%d小时", hourFieldDiff);
@ -1389,12 +1277,9 @@ public class DateUtil {
    /**
     * 1970年1月1日来的 秒转化成时间
     * @param seconds
     * @return
     */
    public static Date secondTransfor(int seconds){
        LocalDateTime localDateTime = LocalDateTime.of(1970,1,1,0,0,0);
        localDateTime.plusSeconds(seconds);
        return Date.from(localDateTime.plusSeconds(seconds).atZone(zone).toInstant());
    }
@ -1402,15 +1287,14 @@ public class DateUtil {
     * 获取指定时间和当前时间的距离
     * 几秒前、几分钟前、几小时前、几天前
     * @param l1 秒级时间戳
     * @return
     */
    public static String getTimeAgeStr(Long l1){
        String timeAgoStr = "";
        String timeAgoStr;
        BigDecimal b1 = new BigDecimal(l1);
        BigDecimal b2 = new BigDecimal(System.currentTimeMillis()/1000);
        BigDecimal subtract = b2.subtract(b1);//秒数
        if(subtract.compareTo(new BigDecimal(60))<0){//小于一分钟前
            timeAgoStr = subtract.toString()+"秒前";
            timeAgoStr = subtract +"秒前";
        }else if(subtract.compareTo(new BigDecimal(3600))<0){//小于一小时
            timeAgoStr = subtract.divide(new BigDecimal(60),0,BigDecimal.ROUND_HALF_DOWN).toString()+"分钟前";
        }else if(subtract.compareTo(new BigDecimal(86400))<0){//小于一天
@ -1425,7 +1309,6 @@ public class DateUtil {
     * 获取指定时间的前后若干时间戳
     * list[0]前
     * list[1]后
     * @return
     */
    public static List<String> getTimeByBeforeAndAfterTime(String time,long l){
        List<String> list = new ArrayList<>();