Java通过date获取前三个月的数据(以当前时间为基准)

Java获取前三个月的数据(以当前时间为基准)

   public static void main(String[] args) {
        Date dNow = new Date();   //当前时间
        Date dBefore = new Date();
        Calendar calendar = Calendar.getInstance(); //得到日历
        calendar.setTime(dNow);//把当前时间赋给日历
        calendar.add(Calendar.MONTH, -3);  //设置为前3月
        dBefore = calendar.getTime();   //得到前3月的时间
        System.out.println("前三个月的时间戳为:"+dBefore.getTime());
        System.out.println("当前时间减去前三个月的时间差");
        System.out.println(dNow.getTime()-dBefore.getTime());
        long strarTm = 1056486041591L;
        if ((dNow.getTime()-strarTm)>dNow.getTime()-dBefore.getTime()){
            System.out.println("数据不是前三个月的数据");
        }else{
        	//可放入相对应的数据
            System.out.println("数据是前三个月的数据");
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值