Decrement a date in Java

后端 未结 4 2129
野的像风
野的像风 2021-02-20 03:34

I want to get the previous day (24 hours) from the current time.

e.g if current time is Date currentTime = new Date();

2011-04-25 12:

4条回答
  •  有刺的猬
    2021-02-20 04:30

    please checkout this here: Java Date vs Calendar

    Calendar cal=Calendar.getInstance();
    cal.setTime(date); //not sure if date.getTime() is needed here
    cal.add(Calendar.DAY_OF_MONTH, -1);
    Date newDate = cal.getTime();
    

提交回复
热议问题