javaandroidjava-calendar

How to get correct Index of Week Of Year


I have a string of date which is

String dateOfOrder = "02/06/2019";

and I want to find out the week of the year based on my dateOfOrder. I set my string into the Calender class and I tried using this method which is

int WeekOfYear = c.get(Calendar.WEEK_OF_YEAR);

But when I checked online with http://www.whatweekisit.org/

The expected Week of year I should be getting is Week Number 22 but I end up getting Week Number 23. Anyway to resolve this issue?


Solution

  • Try using like this -

    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR,2019);
    c.set(Calendar.MONTH,06);
    c.set(Calendar.DATE, 02);
    
    Int week = c.get(Calendar.WEEK_OF_YEAR));