好先上写的一个小方法=========
// 处理时间
public String dateDispose(String endTime, String startTime) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = sdf.parse(endTime);
Long l = d1.getTime();
Date d2 = sdf.parse(startTime);
Long p = d2.getTime();
Integer cha = (int) ((l - p) / 1000 / 60 / 60 / 24);
return cha.toString();
}
=======================================mian方法实际应用
String time1="2018-01-02";
String time2="2018-01-01";
String lll = dateDispose(time2,time1);
System.out.println(lll+"天");
很简单啊,在实际业务中 time1 time2 就是你在数据库查询出来的值 如下我自己的实际业务
// 获取所有的项目合同信息详情
List<TbContractInfoEntity> proContractInfoList = contractMapper.getAllProContractInfo();
for (TbContractInfoEntity contractInfoEntity : proContractInfoList) {
// 招标申请(偏差时间)
if ((!"".equals(contractInfoEntity.getFdCfbApplyforRealityTime())
&& contractInfoEntity.getFdCfbApplyforRealityTime() != null
&& !"".equals(contractInfoEntity.getFdCfbApplyforPlanTime())
&& contractInfoEntity.getFdCfbApplyforPlanTime() != null)) {
contractInfoEntity.setFdCfbApplyforBiasTime(dateDispose(contractInfoEntity.getFdCfbApplyforRealityTime(),
contractInfoEntity.getFdCfbApplyforPlanTime()));
}
}
好了到此结束了。。。希望能对诸位有帮助代码已经很详细了