两个时间段得到几年几月几日的格式

public static String dayComparePrecise(String fromDate, String toDate){

    Period period = Period.between(LocalDate.parse(fromDate), LocalDate.parse(toDate));

    StringBuffer sb = new StringBuffer();
    sb.append(period.getYears()).append(",")
            .append(period.getMonths()).append(",")
            .append(period.getDays());
    String s = sb.toString();
    String[] temp1 = s.split(",");
    String a1 = temp1[1];
    String qq ="";

        String[] temp = s.split(",");
        String s1 = temp[0];
        String s2 = temp[1];
        String s3 = temp[2];
    if (s1.equals("0")){
        if (s2.equals("0")){
            qq=s3+"天";
        }else {
            qq=s2+"月"+s3+"天";
        }if (s2.equals("0")){
            if (s3.equals("0")){
                qq=s1+"年";
            }if (s1.equals("0")){
                 qq =s3+"天";
            } else {
                qq=s1+"年"+s3+"天";
            }
        }if (s3.equals("0")){
            if (s2.equals("0")){
                qq=s1+"年";
            }if (s1.equals("0")){
                qq = s2+"月";
            }
            else {
                qq=s1+"年"+s2+"月";
            }
        }
    }else {
        qq = s1+"年"+s2+"月"+s3+"天";
    }

    return qq;
}

你可能感兴趣的:(两个时间段得到几年几月几日的格式)