错误示范:
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);//获取一个月前的今天
这种写法假设传入的日期为2019-03-31,得到的结果是2019-03-03,2月31号-->推到了3月3号



正确写法:
calendar.add(Calendar.MONTH, -1);
传入的日期为2019-03-31,得到的结果是2019-02-28,推荐使用

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
猜你喜欢
  • 2021-06-04
  • 2021-12-28
  • 2022-12-23
  • 2021-12-08
  • 2022-01-17
  • 2021-08-28
  • 2022-12-23
相关资源
相似解决方案