SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date currentTime = new Date(); String currentTimeStr = simpleDateFormat.format(currentTime);

if (StringUtils.isEmpty(currentTimeStr)) { currentTimeStr = DateUtil.dateToString(new Date(), DateUtil.getFormatter(16)); }

if (!StringUtils.hasLength(currentTimeStr) || !StringUtils.hasLength(patientInfo.get("birthday"))) { return ResultGenerator.genFailedResult("参数缺失"); }

int[] timeIntervalArray; try { Date currentTimeDate = simpleDateFormat.parse(currentTimeStr); Date birthdayDate = simpleDateFormat.parse(patientInfo.get("birthday")); timeIntervalArray = DateUtil.getTimeIntervalArray(currentTimeDate, birthdayDate);

if (timeIntervalArray[0] > 0) {
    certInpatientDTO.setUnit("岁");
} else if (timeIntervalArray[1] > 0) {
    certInpatientDTO.setUnit("月");
} else if (timeIntervalArray[2] > 0) {
    certInpatientDTO.setUnit("日");
} else if (timeIntervalArray[3] > 0) {
    certInpatientDTO.setUnit("时");
} else if (timeIntervalArray[4] > 0) {
    certInpatientDTO.setUnit("分");
}

} catch (ParseException e) { return ResultGenerator.genFailedResult("日期转换错误"); }

SimpleDateFormat simpleDateFormat = new SimpleDateFormatyyyy-MM-dd HHmm; 获取当前时间 Date currentTime = new Date; 格式化当前时间为字符串 String currentTimeStr = simpleDat

原文地址: https://www.cveoy.top/t/topic/i5SI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录