1

I try to get the "week of year", so the question is basically that I use this code to obtain the week of year but this give me wrong week. for example today is 27/04/16 so this code brings me 18 but I search online and the real week is 17. Whats I need to change in my code to get the week 17 ?

I try this..

    Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date());  
    weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);

And this.

    Calendar calendar = Calendar.getInstance()
    calendar.setTime(new Date());  
    weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);

In Wikipedia https://en.wikipedia.org/wiki/ISO_week_date#First_week

April have this weeks 14 to 17 May 18 to 22

This code is in Java 7 Android. Help me. please.

Thanks

exequielc
  • 681
  • 1
  • 11
  • 32

1 Answers1

2

So, the answer is use the German Locale to get the Week 17 of the year. In the ISO8901.

Calendar calDe = Calendar.getInstance(Locale.GERMAN);
calDe.setTime(new Date());
weekOfYear = calDe.get(Calendar.WEEK_OF_YEAR);
exequielc
  • 681
  • 1
  • 11
  • 32