用日历实际添加月份中的天数

时间:2017-07-18 06:25:42

标签: android calendar

我正在为我的国家/地区创建日历不同的日历。我们的日历在2月份有31天,默认情况下我只有28天。如何再添加3天并使其达到31?

  int  daysInMonth[]={31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30}
  // I want to show calendar days up to 31 for jan, 31 for feb, 31 for march, 32 for April and show on.
 How can I achieve this?

 public void updateCalendar(HashSet<Date> events)
{
    ArrayList<Date> cells = new ArrayList<>();

    Calendar calendar = (Calendar)currentDate.clone();
    Log.d("myError1",""+calendar);

    // determine the cell for current month's beginning
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int monthBeginningCell = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    Log.d("myError2",""+monthBeginningCell);

    // move calendar backwards to the beginning of the week
    calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);

    // fill cells
    while (cells.size() < DAYS_COUNT)
    {
        cells.add(calendar.getTime());
        //calendar.add(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DAY_OF_MONTH,1);
        if (Calendar.MONTH==1){
            calendar.add(Calendar.DAY_OF_WEEK,3);
        }
    }

    // update grid
    grid.setAdapter(new CalendarAdapter(getContext(), cells, events));

    // update title
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    txtDate.setText(sdf.format(currentDate.getTime()));

0 个答案:

没有答案