Java Utililty Methods Month Get

List of utility methods to do Month Get

Description

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

Method

DategetMonthEnd(Date date)
get Month End
int year = Integer.parseInt(FormatDate(date, "yyyy"));
int month = Integer.parseInt(FormatDate(date, "MM"));
int day = Integer.parseInt(FormatDate(date, "dd"));
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day, 0, 0, 0);
int monthLength = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
String newDateStr = FormatDate(date, "yyyy") + "-" + FormatDate(date, "MM") + "-";
if (monthLength < 10)
    newDateStr += "0" + monthLength;
...
StringgetMonthEnd(String strdate)
get Month End
java.util.Date date = parseDate(getMonthBegin(strdate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return formatDate(calendar.getTime());
StringgetMonthEnd(String strdate)
get Month End
Date date = parseDate(getMonthBegin(strdate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(2, 1);
calendar.add(6, -1);
return formatDate(calendar.getTime());
StringgetMonthEndDate(Date date)
get Month End Date
GregorianCalendar gc = new GregorianCalendar();
gc.add(GregorianCalendar.MONTH, 1);
gc.add(GregorianCalendar.DATE, -date.getDate());
Date dateTemp = gc.getTime();
return date2String(dateTemp);
StringgetMonthFirstDate(final Date date, final String format)
get Month First Date
Date monthFirstDate = getMonthFirstDate(date);
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(monthFirstDate);
intgetMonthForDate(String dateToCheck, String pattern)
Parses a string into a date.
if (isDateValid(dateToCheck, pattern) && dateToCheck.length() == pattern.length()) {
    int index = pattern.indexOf("MM"); 
    if (index == -1) {
        return (-1);
    String month_str = dateToCheck.substring(index, index + 2);
    int month = -1;
    try {
...
StringgetMonthForInt(int num)
get Month For Int
String month = "wrong";
DateFormatSymbols dfs = new DateFormatSymbols();
String[] months = dfs.getMonths();
if (num >= 0 && num <= 11) {
    month = months[num];
return month;
intgetMonthForString(String monthStr, Locale locale)
Parses a string (representing a month) and returns it's corresponding value as a Calendar month.
DateFormatSymbols dfs = new DateFormatSymbols(locale);
String[] months = dfs.getMonths();
for (int i = 0; i < months.length; i++) {
    if (months[i].toLowerCase(locale).startsWith(monthStr.toLowerCase(locale))) {
        return i + 1;
return -1;
...
StringgetMonthInfo(int monthInfo)
get Month Info
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.MONTH, monthInfo - 1);
SimpleDateFormat formatter = new SimpleDateFormat("MMM");
return formatter.format(cal.getTime());
longgetMonthLength(String countDate)
get Month Length
String firstDay = countDate.substring(0, countDate.length() - 2) + "01";
Date startDate = strToDate(firstDay);
Date endDate = getNextMonth(startDate, new Long(1));
long startDateTime = startDate.getTime();
long endDateTime = endDate.getTime();
long dayTime = 24 * 60 * 60 * 1000;
long days = (endDateTime - startDateTime) / dayTime;
return days;
...