[轉]java获得指定时间几天前或几天后的日期
轉自: http://wangyu.javaeye.com/blog/569829
- /**
- * 得到几天前的时间
- *
- * @param d
- * @param day
- * @return
- */
- public static Date getDateBefore(Date d, int day) {
- Calendar now = Calendar.getInstance();
- now.setTime(d);
- now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
- return now.getTime();
- }
- /**
- * 得到几天后的时间
- *
- * @param d
- * @param day
- * @return
- */
- public static Date getDateAfter(Date d, int day) {
- Calendar now = Calendar.getInstance();
- now.setTime(d);
- now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
- return now.getTime();
- }
以上是 [轉]java获得指定时间几天前或几天后的日期 的全部内容, 来源链接: utcz.com/z/393590.html