Java Utililty Methods Year Month

List of utility methods to do Year Month

Description

The list of methods to do Year Month are organized into topic(s).

Method

DateencodeDateTime(int year, int month, int day, int hour, int minutes, int seconds)
Return a date.
Date result;
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, day, hour, minutes, seconds);
result = calendar.getTime();
return result;
DategetAddedDate(Date date, int addYear, int addMonth, int addDay, int addHour, int addMinute, int addSecond)
get Added Date
Calendar nowdate = new GregorianCalendar();
nowdate.setTime(date);
nowdate.add(Calendar.YEAR, addYear);
nowdate.add(Calendar.MONTH, addMonth);
nowdate.add(Calendar.DAY_OF_MONTH, addDay);
nowdate.add(Calendar.HOUR_OF_DAY, addHour);
nowdate.add(Calendar.MINUTE, addMinute);
nowdate.add(Calendar.SECOND, addSecond);
...
ListgetAllDate(String year_month)
get All Date
List<Object> list = new ArrayList<Object>();
Calendar rightNow = Calendar.getInstance();
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM");
try {
    rightNow.setTime(simpleDate.parse(year_month));
} catch (ParseException e) {
    e.printStackTrace();
int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
String date = "";
for (int i = 1; i <= days; i++) {
    if (i < 10) {
        date = year_month + "-0" + i;
    } else {
        date = year_month + "-" + i;
    list.add(date);
return list;
Date[]getBeginEndDayOfMonth(String yearMonthString)
Get the begin/end day of a month
try {
    Date begin, end;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
    begin = sdf.parse(yearMonthString);
    Calendar cal = getCalendar();
    cal.setTime(begin);
    cal.add(Calendar.MONTH, 1);
    cal.add(Calendar.MILLISECOND, -1);
...
DategetCurrentYearMonthDay()
get Current Year Month Day
Date date = new Date();
return new Date(date.getYear(), date.getMonth(), date.getDate());
StringgetCurYearMonth()
get Cur Year Month
Calendar now = Calendar.getInstance(TimeZone.getDefault());
String DATE_FORMAT = "yyyyMM";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
sdf.setTimeZone(TimeZone.getDefault());
return (sdf.format(now.getTime()));
DategetDate(int year, int month, int day)
get Date
return getDate(year, month, day, 0, 0, 0);
DategetDate(int year, int month, int day, int hour, int minute)
get Date
Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month), day, hour, minute);
return cal.getTime();
intgetDaysOfMonth(String year, String month)
get Days Of Month
int days = 0;
if (month.equals("1") || month.equals("3") || month.equals("5") || month.equals("7") || month.equals("8")
        || month.equals("10") || month.equals("12")) {
    days = 31;
} else if (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")) {
    days = 30;
} else {
    if ((Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0)
...
DategetEndDateOfMonth(int year, int month)
get End Date Of Month
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
String enddat = year + "-" + (month + 1) + "-" + cal.getActualMaximum(Calendar.DATE);
Date enddate = sdf.parse(enddat);
return enddate;