Java日历时间,分钟是错误的 [英] Java calendar time, minute is wrong

查看:27
本文介绍了Java日历时间,分钟是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么 java.util.Caldendar 中的 MINUTE 方法返回错误的分钟吗?

Anyone know why the MINUTE method in java.util.Caldendar returns an incorrect minute?

import java.util.Calendar;

public class Clock
{
    // Instance fields
    private Calendar time;

    /**
     * Constructor. Starts the clock at the current operating system time
     */
    public Clock()
    {
       System.out.println(this.time.HOUR_OF_DAY+":"+this.time.MINUTE);
    }
}

推荐答案

Calendar.MINUTE 不是实际的分钟,而是传递到get()"以获取值的常量索引值.例如:

Calendar.MINUTE isn't the actual minute but rather a constant index value to pass into "get()" in order to get the value. For example:

System.out.println(this.time.get(Calendar.HOUR_OF_DAY) + ":" + this.time.get(Calendar.MINUTE));

这篇关于Java日历时间,分钟是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆