calendar获取前一小时

 public static void main(String[] args) throws Exception {
        System.out.println();
        Calendar calendar = new GregorianCalendar();
        calendar.set(Calendar.HOUR_OF_DAY, new Date().getHours()-1);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date hourStart = calendar.getTime();
        calendar.add(Calendar.HOUR, 1);
        calendar.add(Calendar.MINUTE, 1);
        Date hourEnd = calendar.getTime();
        System.out.println("hourStart:"+hourStart);
        System.out.println("hourEnd:"+hourEnd);
    }

你可能感兴趣的:(java,java)