java 查詢當天0點0分0秒


由於業務需求,要計算客戶今日收益,本周本月,本年等收益,

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()為獲取當前系統時間

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM