本文介绍了在Java中找出最近30天,60天和90天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一些记录与receivedDate。我想从收到的日期取得最后30或60或90天的记录。如何解决?

解决方案

使用。

  Date today = new Date(); 
日历cal = new GregorianCalendar();
cal.setTime(今天);
cal.add(Calendar.DAY_OF_MONTH,-30);
日期今天30 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH,-60);
日期today60 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH,-90);
Date today90 = cal.getTime();


How to get last 30 / 60 / 90 days records from given date in java?

I have some records with receivedDate. I want to fetch the records for last 30 or 60 or 90 days from received Date. How to resolve it?

解决方案

Use java.util.Calendar.

Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -30);
Date today30 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, -60);
Date today60 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, -90);
Date today90 = cal.getTime();

这篇关于在Java中找出最近30天,60天和90天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 00:46