Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR)奇怪 [英] Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR) weirdness

查看:525
本文介绍了Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR)奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白方法 getActualMaximum(int)或字段WEEK_OF_YEAR,或有一个太阳错误涉及(或所有三个)...有人可以解释(至少在德语区域设置 ...)中输入以下代码:

  .setDefault(Locale.GERMAN); 
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR,2010);
c.set(Calendar.MONTH,0);
c.set(Calendar.DAY_OF_MONTH,1);
System.out.println(max:+ c.getActualMaximum(Calendar.WEEK_OF_YEAR));
System.out.println(actual:+ c.get(Calendar.WEEK_OF_YEAR));

产生以下输出:

  max:52 
actual:53

getActualMaximum(int)


返回
指定的日历字段可以有,
给出此日历的时间值。
例如,MONTH字段的实际最大值
在某些
年中为12,而在其他年份中为13在希伯来历日历系统中为







编辑 b

情节变厚。 在英语区域设置 -Duser.language = en -Duser.country = us )输出为:

  max:52 
actual:1


$ b

解决方案

这个信息是正确的:

p>

 最大:52 
实际:53

2010年最多有52周。实际星期是53,因为2009年有最大53周,大多数星期从星期天或星期一开始。第1周在大多数情况下是一年的第一个星期,在1月有4天。由于1月1日的星期在2010年只有2或3天,所以这一周被认为是2009年的一部分。



很可能英语语言环境有不同的规则



维基百科正确地解释了这一点: wikipedia week article


Either I don't understand the method getActualMaximum(int) or the field WEEK_OF_YEAR, or there's a Sun bug involved (or all three)...could someone explain to me why (at least in a German locale...) the following code:

    Locale.setDefault( Locale.GERMAN );
    Calendar c = Calendar.getInstance();
    c.set( Calendar.YEAR, 2010 );
    c.set( Calendar.MONTH, 0 );
    c.set( Calendar.DAY_OF_MONTH, 1 );
    System.out.println("max:    "+c.getActualMaximum( Calendar.WEEK_OF_YEAR ));
    System.out.println("actual: "+c.get( Calendar.WEEK_OF_YEAR ));

produces the following output:

    max:    52
    actual: 53

Here's the Javadoc of getActualMaximum(int):

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar. For example, the actual maximum value of the MONTH field is 12 in some years, and 13 in other years in the Hebrew calendar system.


Edit

The plot thickens. In an English locale (-Duser.language=en -Duser.country=us) the output is:

    max:    52
    actual: 1

Seems to point to it being a Sun bug for German locales?

解决方案

This information is correct:

max:    52
actual: 53

The year 2010 has a maximum of 52 weeks. The actual week is 53, since 2009 has maximum 53 weeks and most weeks start on sunday or monday. Week 1 is in most cases the first week of the year with 4 days in january. Since the week of the january 1st has only 2 or 3 days in 2010, the week is considered part of 2009.

Most likely the english locale has different rules for determing week 1, like the first week is the week of january 1st.

Wikipedia explains it correctly: wikipedia week article

这篇关于Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR)奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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