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

前端 未结 11 1593
北荒
北荒 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条回答
  •  醉酒成梦
    2020-12-14 06:16

    I always recommend Joda for this sort of stuff. It has a much nicer API, and doesn't suffer from threading issues that the standard Java date/time has (e.g. issues with SimpleDateFormat, or general mutability).

    e.g.

    DateTime result = dt.minusMonths(3);
    

提交回复
热议问题