How to get previous 7 dates from a particular date in java?I am getting 7 dates from present date, but I want from particular date

前端 未结 3 813
暖寄归人
暖寄归人 2020-12-07 06:20
//explain
public class DateLoop {
    static String finalDate; 
    static String particularDate;

    public static void main(String[] args) {
        // TODO Auto-         


        
3条回答
  •  旧时难觅i
    2020-12-07 06:57

    if you want to have some date from some data do something like below.

    public void dateFromRandomDate(String date){
        SimpleDateFormat formatter2=new SimpleDateFormat("dd-MMM-yyyy");  
        Date date2=formatter2.parse(date); 
        Calendar calendar = Calendar.getInstance();
        //this sets the date to given date
        calendar.calendar.setTime(date2);
        //now call getTime() or add ,subtract date from here
        //this will add 1 year to given one,similarlly others will work.
        calendar.add(Calendar.YEAR,1);
    }
    

提交回复
热议问题