为什么2010年12月31日作为一年的周回报1? [英] Why dec 31 2010 returns 1 as week of year?

查看:175
本文介绍了为什么2010年12月31日作为一年的周回报1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

Calendar c = Calendar.getInstance();
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
c.setTime( sdf.parse("31/12/2010"));
out.println( c.get( Calendar.WEEK_OF_YEAR ) );  

打印1

时间。

:)

推荐答案

年份为 区域设置

The definition of Week of Year is Locale dependent.

如何在美国定义在其他帖子中被丢弃。例如在德国( DIN 1355-1 / ISO 8601 ):年的第一个星期*是新年的第一个星期,有4天或更多天。

How it is defined in US is discused in the other posts. For example in Germany (DIN 1355-1 / ISO 8601): the first Week* of Year is the first week with 4 or more days in the new year.

em>

*first day of week is Monday and last day of week is Sunday

>注意语言环境。例如:

And Java’s Calendar pays attention to the locale. For example:

public static void main(String[] args) throws ParseException {

    DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date lastDec2010 = sdf.parse("31/12/2010");

    Calendar calUs = Calendar.getInstance(Locale.US);       
    calUs.setTime(lastDec2010);

    Calendar calDe = Calendar.getInstance(Locale.GERMAN);       
    calDe.setTime(lastDec2010);

    System.out.println( "us: " + calUs.get( Calendar.WEEK_OF_YEAR ) ); 
    System.out.println( "de: " + calDe.get( Calendar.WEEK_OF_YEAR ) );
}

列印:

us: 1
de: 52

strong> ADDED
对于美国(我可以认为它对墨西哥来说是一样的)1.一年的周是1月属于的星期。 - 所以如果1. Januar是星期六,那么星期五之前(12月31日)属于同一周,在这种情况下,这一天属于2011年的周一。

ADDED For the US (and I can think of that it is the same for Mexico) the 1. Week of Year is the week where the 1. January belongs to. -- So if 1. Januar is a Saturday, then the Friday before (31. Dec) belongs the same week, and in this case this day belongs to the 1. Week of Year 2011.

这篇关于为什么2010年12月31日作为一年的周回报1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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