某个时间之前或之后多少天

public class DateUtil {
	public static void main(String[] args) {
		try {
			System.out.println(addDate("2014-09-09",22));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	public static String addDate(String d, long day) throws ParseException {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sf.parse(d);
		long time = date.getTime();
		day = day * 24 * 60 * 60 * 1000;
		time += day;
		return sf.format(new Date(time));
	}
}

 

你可能感兴趣的:(时间)