How can I build a list of days, months, years from a calendar object in Java?

前端 未结 5 774
闹比i
闹比i 2021-01-06 14:46

I want to build a date widget for a form, which has a select list of months, days, years. since the list is different based on the month and year, i cant hard code it to 31

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 15:24

    The Calendar object will tell you the number of days in the current month using getActualMaximum(Calendar.DAY_OF_MONTH). See an example here.

    From that you can update your lists on each change.

提交回复
热议问题