Getting 18 years before date from calender

前端 未结 2 1739
挽巷
挽巷 2021-01-23 07:01

I need to get complete date(dd/mm/yyyy) which is 18 years from now. i used code as Calendar calc = Calendar.getInstance(); calc.add(Calendar.YEAR, -18); which retrives 18 years

2条回答
  •  旧巷少年郎
    2021-01-23 07:33

    I would recommend using Joda Time, as it will make date manipulation and math very easy. For example:

    DateTime futureDate = new DateTime();
    futureDate.minusYears(18).minusDays(1);
    futureDate.toDate(); // return a regular Date object
    

提交回复
热议问题