ITeye博客

获取前n天的日期

BlueSkator · 2014-09-22 11:20 · java Web · Web前端 · 日期处理 · Markdown

public static String getNextFewDays(String currentDateString,
			Integer offsetDays) {
		Date tempdate = null;
		try {
			tempdate = new SimpleDateFormat().parse(currentDateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		for (int i = 0; i < offsetDays; i++) {
			Calendar cale = Calendar.getInstance();
			cale.setTime(tempdate);
			cale.add(Calendar.DATE, -1);
			tempdate = cale.getTime();
		}

		return new SimpleDateFormat().format(tempdate);
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。