java得到某时间前2小时的时间

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Calendar calendar = Calendar.getInstance();
Date date = sdf.parse(“2019-05-14 02:56:24”);
calendar.setTime(date);
for (int i = 1; i < 31; i++) {
calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY) - 2);
System.out.println(sdf.format(calendar.getTime()));
}

你可能感兴趣的:(java得到某时间前2小时的时间)