业务小方法

1.获取180天后的时间

Instant instant = claimManHourCoefficient.getCrtTime().toInstant();
        System.out.println(claimManHourCoefficient.getCrtTime()+"***********************************");
        ZoneId zoneId = ZoneId.systemDefault();

        // atZone()方法返回在指定时区从此Instant生成的ZonedDateTime。
        LocalDate today = instant.atZone(zoneId).toLocalDate();
        LocalDate after180Days = today.plusDays(180);
        System.out.println(after180Days+"*************************************************************************");

2.五位数编码

 /**
     * 5位数 00001 - 99999
     * @param num
     * @return
     */
    public static String getFiveNumber(int num)
    {
        num++;
        String result = "";
        switch ((num+"").length()) {
            case 1:
                result = "0000" + num;
                break;
            case 2:
                result = "000" + num;
                break;
            case 3:
                result = "00" + num;
                break;
            case 4:
                result = "0" + num;
                break;
            case 5:
                result = "" + num;
                break;
            // 此处代表编号已经超过了9999,从0重新开始
            default:
                result = "00001";
                break;
        }
        return result;
    }

3.获取当前时间年份后两位 和月份的两位

public static String getCurrentYearMonth(){
        String result = "0";
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        String yearStr = String.valueOf(year).substring(2);
        Integer month = calendar.get(Calendar.MONTH) + 1;
        if(month.toString().length() < 2){
            result = 0 + month.toString();
        }
        return yearStr + result;
    }

多个字段降序

list.stream().sorted(Comparator.comparing(类::属性一,Comparator
.reverseOrder()).thenComparing(类::属性二,Comparator.reverseOrder()));

多个字段升序

list.stream().sorted(Comparator.comparing(类::属性一)
.thenComparing(类::属性二));

你可能感兴趣的:(java,servlet,开发语言)