gpt4 book ai didi

java - java.util.calendar 中错误的默认字段值

转载 作者:行者123 更新时间:2023-11-29 06:40:17 32 4
gpt4 key购买 nike

我正在创建 java.util.Calendar 类的实例:

Calendar rightNow = Calendar.getInstance();

getInstance() 使用默认时区和语言环境获取一个 Calendar...现在是波兰的 20:22 1.11.2012,但是当我打印 rightNow字段出来,结果是错误的:

System.out.print(rightNow.get(Calendar.MONTH));
result: 10.

System.out.print(rightNow.get(Calendar.DAY_OF_MONTH));
result: 1.

System.out.print(rightNow.get(Calendar.DATE));
result: 1.

我假设在 12 月 YEAR 字段也将是错误的。谁能给我解释一下?

最佳答案

当你使用日历而不是从 1 时,月份从 0 开始

根据 javadoc

Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

关于java - java.util.calendar 中错误的默认字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13184172/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com