java.util.Date - Deleting three months from a date?

前端 未结 11 1594
北荒
北荒 2020-12-14 05:30

I have a date of type java.util.Date

I want to subtract three months from it.

Not finding a lot of joy in the API.

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 06:12

    String startDate="15/10/1987";

        Date date = new SimpleDateFormat("dd/MM/yyyy").parse(startDate);
        String formattedDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
        LocalDate today = LocalDate.parse(formattedDate);
        String endDate=today.minusMonths(3).toString();
    

提交回复
热议问题