Java Utililty Methods Month Day

List of utility methods to do Month Day

Description

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

Method

StringgetMonthLastDay()
get Month Last Day
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
return formatDateY_M_D(calendar.getTime());
StringgetMonthLastDay(String curmonth, int month)
get Month Last Day
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
Date mydate = formatter.parse(curmonth);
Calendar cal = Calendar.getInstance();
cal.setTime(mydate);
cal.add(Calendar.MONTH, month);
SimpleDateFormat daytime = new SimpleDateFormat("yyyyMMdd");
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
return daytime.format(cal.getTime());
...
DategetMonthLastDay(String dateString)
return the last day of the date's month of specified string value in format: yyyy-MM
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
Date date = null;
try {
    date = simpleDateFormat.parse(dateString);
} catch (Exception e) {
    e.printStackTrace();
Calendar calendar = Calendar.getInstance();
...
StringgetMonthLastDay(String fmt)
get Month Last Day
String returndate = "";
Date date = null;
Calendar cl = Calendar.getInstance();
switch (cl.get(2)) {
case 0:
    cl.set(5, 31);
    break;
case 1:
...
StringgetMonthMaxDay(String sDate)
get Month Max Day
SimpleDateFormat sdf_full = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date date = null;
try {
    date = sdf_full.parse(sDate + "-01");
} catch (ParseException e) {
    e.printStackTrace();
cal.setTime(date);
int last = cal.getActualMaximum(Calendar.DATE);
return String.valueOf(last);
intgetMonthWeek(String curday)
get Month Week
try {
    java.util.Date date = str2date(curday);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(date);
    return rightNow.get(Calendar.WEEK_OF_MONTH);
} catch (Exception e) {
    e.printStackTrace();
    return 0;
...
intgetMonthWeek(String curday)
get Month Week
try {
    java.util.Date date = str2utilDate(curday);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(date);
    return rightNow.get(Calendar.WEEK_OF_MONTH);
} catch (Exception e) {
    System.out.println("DateUtil.getYearWeek(str) Error:e = " + e);
    return 0;
...
StringgetPreviosMonthFirstDay()
get Previos Month First Day
String curYearMonth = getDateTime6String();
String yearMonth = getPreviousYearMonth(curYearMonth);
return yearMonth.substring(0, 4) + "-" + yearMonth.substring(4) + "-01";
StringgetShortFirstDayOfMonth()
get Short First Day Of Month
Calendar cal = Calendar.getInstance();
Date dt = new Date();
cal.setTime(dt);
cal.set(Calendar.DAY_OF_MONTH, 1);
DateFormat df = getNewDateFormat(shortFormat);
return df.format(cal.getTime());
StringgetStringOfFirstDayInMonth()
get String Of First Day In Month
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
String temp = sdf.format(date);
String firstDayInMoth = "";
firstDayInMoth = temp + "-01";
return firstDayInMoth;