jo10
jo10

Reputation: 111

Array of days in a month and get the value from each position

Here is my data structure which is all the days in february. How can i make the day today to be equal from the data for example today is 22 = 21. enter image description here

Here is my current code

 SimpleDateFormat day = new SimpleDateFormat("dd");
                Calendar calendar = Calendar.getInstance();

                int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


                ArrayList<String> allDays = new ArrayList<>();
                for(int i = 0; i < daysInMonth; i++){

                    allDays.add(day.format(calendar.getTime()));


                }

Upvotes: 1

Views: 381

Answers (1)

Prayag Gediya
Prayag Gediya

Reputation: 1118

try with this code,

SimpleDateFormat day = new SimpleDateFormat("dd");
        Calendar calendar = Calendar.getInstance();

        List<String> allDays = new ArrayList<>();
        for(int i = 0; i < calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
            allDays.add(i, String.valueOf(i+1));
        }

this will be your allDays list.

Upvotes: 1

Related Questions