日期类型的时间加减计算

好先上写的一个小方法=========

// 处理时间
        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()));
                }

}

好了到此结束了。。。希望能对诸位有帮助代码已经很详细了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值