Java日历时间、分钟错误

标签 java time

有人知道为什么 java.util.Caldendar 中的 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()”以获取值的常量索引值。例如:

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

关于Java日历时间、分钟错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/404278/

相关文章:

java - 找不到能够从类型 [java.util.LinkedHashMap<?, ?>] 转换为类型 [java.lang.String] 的转换器 - Spring 配置服务器

java - Tomcat 提示一个线程没有被停止

java - HashMap 到 csv/excel 很容易吗?

r - r 中 cat 输出的时间格式

validation - 每个整数都是可能的年份值吗?

java - 从字符串中提取 TimeZone 对象的最佳方法?

Java:有没有办法获得压缩字节数组的预期未压缩长度?

c++ - 从 time_point + duration 到 duration 的转换在 clang 上失败

javascript - 我应该如何更新时间?新日期或setInterval?

java - 如何在java中使用TimeUnit