如何使用Java日历从日期中减去X天? [英] How to subtract X days from a date using Java calendar?

查看:155
本文介绍了如何使用Java日历从日期中减去X天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道使用Java日历从日期中减去X天的简单方法?

Anyone know a simple way using Java calendar to subtract X days from a date?

我没有找到任何函数,允许我直接减去X天从Java的日期。有人可能指向正确的方向吗?

I have not been able to find any function which allows me to directly subtract X days from a date in Java. Can someone point me to the right direction?

推荐答案

取自这里的文档


根据>日历规则,将指定的时间量添加或减少到给定日历字段。例如,要从日历的当前时间减去5天,可以通过调用以下方式实现:

Adds or subtracts the specified amount of time to the given calendar field, based on the > calendar's rules. For example, to subtract 5 days from the current time of the calendar, > you can achieve it by calling:

Calendar calendar = Calendar.getInstance(); // this would default to now
calendar.add(Calendar.DAY_OF_MONTH, -5).


这篇关于如何使用Java日历从日期中减去X天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆