Java Day getDaysByYearMonth(String ym)

Here you can find the source of getDaysByYearMonth(String ym)

Description

get Days By Year Month

License

Apache License

Declaration

public static List<String> getDaysByYearMonth(String ym) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import java.util.Date;
import java.util.GregorianCalendar;

import java.util.List;

public class Main {

    public static List<String> getDaysByYearMonth(String ym) {
        List<String> list = new ArrayList<String>();
        int maxDate = getMaxDayByYearMonth(ym);
        for (int i = 1; i <= maxDate; i++) {
            String d = String.valueOf(i < 10 ? "0" + i : i);
            list.add(ym + "-" + d);
        }/*from w w  w. j  ava2s .  c  o  m*/
        return list;
    }

    public static int getMaxDayByYearMonth(String ym) {
        int day = 0;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            Calendar calendar = new GregorianCalendar();
            Date date = sdf.parse(ym);
            calendar.setTime(date);
            day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        } catch (ParseException e) {
            day = 0;
        }
        return day;
    }
}

Related

  1. getDayRange(String bday, String eday)
  2. getDays(Date day, int preDays, String format)
  3. getDays(Date sd, Date ed)
  4. getDays(String yyyy)
  5. getDaysAgo(int interval)
  6. getDaysForDate(String date)
  7. getDaysforYear()
  8. getDaysFrom2Dates(Calendar calendar1, Calendar calendar2)
  9. getDaysLater(int day)