由于业务需求,要计算客户今日收益,本周本月,本年等收益,
1.查询当天0点0分0秒
2.查询本月一号0点0分0秒
......
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
Calendar calendar2 = Calendar.getInstance();
calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), 1, 0, 0, 0);
Calendar calendar3 = Calendar.getInstance();
calendar3.set(calendar3.get(Calendar.YEAR), 0, 1, 0, 0, 0);
Date beginOfDate = calendar.getTime();
Date beginOfDate2 = calendar2.getTime();
Date beginOfDate3 = calendar3.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(formatter.format(beginOfDate)); //今日
System.out.println(formatter.format(beginOfDate2)); //本月
System.out.println(formatter.format(beginOfDate3)); //本年
System.out.println(formatter.format(new Date()));// new Date()为获取当前系统时间