为什么en_GB语言环境认为1月1日是一年的第52周? [英] Why does the en_GB locale think the 1st of January is the 52nd week of the year?

查看:185
本文介绍了为什么en_GB语言环境认为1月1日是一年的第52周?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实证明,对于区域设置为en_GB的2011年1月1日,使用ww作为Java日期格式字符串的一年中的星期为52.这是证明(使用scala REPL,尽管我可以使用Java程序完成此操作)

It turns out that the week-of-year using ww as a java date format string is 52 for the 1st January 2011 when the locale is en_GB. Here is proof (using a scala REPL, though I could have done this using a Java program)

首先获取我的语言环境

scala> val en = java.util.Locale.getAvailableLocales.find(_.toString == "en") getOrElse error("no en")
en: java.util.Locale = en

scala> val en_GB = java.util.Locale.getAvailableLocales.find(_.toString == "en_GB") getOrElse error("no en_GB")
en_GB: java.util.Locale = en_GB

现在是1月1日

scala> import java.util.Calendar; import Calendar._
import java.util.Calendar
import Calendar._

scala> Calendar.getInstance
res23: java.util.Calendar = java.util.GregorianCalendar[time=1300708839128,....]

scala> res23.set(MONTH, JANUARY); res23.set(DAY_OF_MONTH, 1)

scala> val firstJan = res23.getTime
firstJan: java.util.Date = Sat Jan 01 12:00:39 GMT 2011

现在声明一种方法,以一种依赖于语言环境的方式打印此方法:

Now declare a method to print this in a locale-dependent way:

scala> def weekInLocale(l : java.util.Locale) = { java.util.Locale.setDefault(l); new java.text.SimpleDateFormat("ww").format(firstJan) }
weekInLocale: (l: java.util.Locale)java.lang.String

现在调用它:

scala> weekInLocale(en)
res24: java.lang.String = 01

scala> weekInLocale(en_GB)
res26: java.lang.String = 52

这是对的吗

推荐答案

从ISO8601开始,第1周定义为包含1月4日的一周.由于2011年1月1日是星期六,因此该周是前一周.

From ISO8601, week 1 is defined as the week containing January 4th. Since 2011-01-01 was a Saturday, this falls in the previous week.

由于没有第0周,因此2011-01-01也可以拼写为2010-W52-6.

Since there is no week 0, then 2011-01-01 can also be spelled as 2010-W52-6.

另一方面,那些古怪的美国人只能呆上几个星期.来自维基百科:

Those wacky Americans, on the other hand, allow for partial weeks. From Wikipedia:

美国系统从周日起有几周的时间 到星期六,以及在 年初和年终.

The US system has weeks from Sunday through Saturday, and partial weeks at the beginning and the end of the year.

因此,他们将其定义为第1周的最后一天.

So, they would define it as being the last day of week 1.

这篇关于为什么en_GB语言环境认为1月1日是一年的第52周?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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