In the same locale, different week numbers for the same date on different machines are indicated

For a java application, the week number is important to the end user. However, for any reason, the week numbers on the same date and locale are different between my machine and the end user.

We both run Windows 10 64bit and jre1.8.0_101

I created a small program to illustrate the problem, and it gives different results between both machines.

Calendar calUs = Calendar.getInstance(Locale.US); String usToday = "this week US: \t\t\t" + calUs.get(Calendar.WEEK_OF_YEAR) + " (should be 35 on 24-8-2016)"; Calendar calDe = Calendar.getInstance(Locale.GERMAN); String deToday = "this week DE: \t\t\t" + calDe.get(Calendar.WEEK_OF_YEAR) + " (should be 34 on 24-8-2016)"; Calendar calDef = Calendar.getInstance(); String defToday = "this week default default: \t" + calDef.get(Calendar.WEEK_OF_YEAR) + " (should be 34 on 24-8-2016)"; System.out.println("Default locale: " + Locale.getDefault() + "\t(should be nl_NL)"); System.out.println(usToday); System.out.println(deToday); System.out.println(defToday); 

On my machine, this gives:

Default locale: nl_NL (must be nl_NL)

this week USA: 35 (should be 35 on 24-8-2016)

this week DE: 34 (should be 34 on 24-8-2016)

default value this week: 34 (should be 34 on 24-8-2016)

But for the end user, we see incorrect results:

Default locale: nl_NL (must be nl_NL)

this week USA: 35 (should be 35 on 24-8-2016)

this week DE: 35 (should be 34 on 24-8-2016)

default value this week: 35 (should be 34 on 24-8-2016)

I already tried to change the settings for the first day of the week and the first week in the Windows registry in order to try to reproduce the problem without success. In MS Outlook, we get the correct week number on both machines. This makes me think that the problem is somehow limited by java.

What am I missing here?

+8
java
source share
1 answer

I just tested my time testing program on my colleague, who works as she should. It seems that we will work to change the main program to use this library (and, possibly, switch to "Time" when we switch to Java 8)

I suggest not investing too much time to get the Calendar class to interact when working with week numbers in Java.

+1
source share

All Articles