0

How can I get the friday of the 34th week of the year? Not just the friday. Any day, I want to get the current week of the year, and in this week I want the friday. Thanks in advance

kerem_ali
  • 87
  • 1
  • 7

1 Answers1

1

Use the Calendar class:

Calendar c = Calendar.getInstance();
c.setWeekDate(2020, 34, Calendar.FRIDAY);

Then you can access the Date object for this day like this:

System.out.println(c.getTime());

Which will print (for me): Fri Aug 21 15:45:22 CEST 2020.
Or you can even access the individual calendar fields like so:

System.out.println(
    "YEAR: " + c.get(Calendar.YEAR) + "\n" +
    "MONTH: " + c.get(Calendar.MONTH) + "\n" +
    "DAY: " + c.get(Calendar.DAY_OF_MONTH));

This will print:

YEAR: 2020
MONTH: 21
DAY: 7

Just don't make the mistake to try to achieve things like this purely with the help of Date.

bkis
  • 2,530
  • 1
  • 17
  • 31