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

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;
booleanisFirstDayOfMonth()
is First Day Of Month
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.DAY_OF_MONTH) == 1;
booleanisLastDayOfMonth()
Checking the date of the end of Month
try {
    Date today = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(today);
    calendar.add(Calendar.MONTH, 1);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.add(Calendar.DATE, -1);
    Date lastDayOfMonth = calendar.getTime();
...
booleanisLastDayOfMonth(Calendar cal)
is Last Day Of Month
int m1 = cal.get(Calendar.MONTH);
cal.add(Calendar.DAY_OF_MONTH, 1);
int m2 = cal.get(Calendar.MONTH);
cal.add(Calendar.DAY_OF_MONTH, -1);
return m1 != m2;
StringlastDayOfLastMonth()
last Day Of Last Month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, 1);
cal.add(Calendar.DATE, -1);
return String.valueOf(dfDdMMMYYYY.format(cal.getTime()));
Stringlastdayofmonth()
lastdayofmonth
Calendar calendar = Calendar.getInstance();
Calendar cpcalendar = (Calendar) calendar.clone();
cpcalendar.set(Calendar.DAY_OF_MONTH, 1);
cpcalendar.add(Calendar.MONTH, 1);
cpcalendar.add(Calendar.DATE, -1);
String date = yyyyMMdd.format(new Date(cpcalendar.getTimeInMillis()));
return date;
StringlastDayOfMonth(String batdate)
last Day Of Month
Calendar cal = Calendar.getInstance();
Date date = null;
try {
    date = new SimpleDateFormat("yyyyMMdd").parse(batdate);
} catch (ParseException e) {
    e.printStackTrace();
cal.setTime(date);
...
StringlastDayOfMonth(String src)
last Day Of Month
return lastDayOfMonth(src, "yyyyMMdd");
StringpreviousMonthFirstDay()
previous Month First Day
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
Date curDate = new Date(System.currentTimeMillis());
Calendar calendar = Calendar.getInstance();
calendar.setTime(curDate);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return sdf.format(calendar.getTime());