Calender.HOUR_OF_DAY returns 错误的结果

Calender.HOUR_OF_DAY returns wrong results

我已经编写了一段代码来从日历对象中获取小时的值,但是 returns 结果是错误的。

mpleDateFormat sf = new SimpleDateFormat("hh:mm");

    try {
        time = sf.parse("09:00");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(time);

    System.out.println(cal);
    System.out.println(cal.HOUR_OF_DAY);

在第一条语句中,calender 的 toString 方法显示 Hour_OF_DAY 的值为 9,但 cal.HOUR_OF_DAY 打印 11.

Calendar.HOUR_OF_DAY is a constant (with the value 11) meant to be used together with the Calendar#get() 检索小时值的方法:

System.out.println(cal.get(Calendar.HOUR_OF_DAY));

这会打印

9