歪歪歪日

导航

间隔日期转换成:x天 x月 x年x月

实例:

String confirmDateString = hypertension.getConfirmDate();
LocalDate today = LocalDate.now();

LocalDate confirmDate = LocalDate.parse(confirmDateString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

Period p = Period.between(confirmDate, today);
System.out.println(p);

String result = "";
if (p.getDays() > 0) {
result = p.getDays() + "天";
}
if (p.getMonths() > 0) {
result = p.getMonths() + "月";
}
if (p.getYears() > 0) {
result = p.getYears() + "年" + p.getMonths() + "月";
}

hypertension.setDeaseAge(result);
}

posted on 2019-11-07 17:55  妲你小己己  阅读(263)  评论(0编辑  收藏  举报