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

StringgetMonthNo(Date date)
get Month No
SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyyMM");
return sdFormatter.format(date);
StringgetMonthNumber()
Get the number of the current month
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("MM");
String output = format.format(date);
return output;
StringgetMonthOfSeason(Date date, boolean firstOrLast)
get Month Of Season
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
String yearStr = yearFormat.format(date);
String monthStr = monthFormat.format(date);
int month = Integer.parseInt(monthStr);
String array[][] = { { "01", "02", "03" }, { "04", "05", "06" }, { "07", "08", "09" },
        { "10", "11", "12" } };
int season = 1;
...
StringgetMonthPath(Date date)
get Month Path
return new SimpleDateFormat(MONTH_FORMAT_DATEPATH).format(date);
ListgetMonthRange(String strBeginDate, String strEndDate, String pattern)
get Month Range
List<String> ret = new ArrayList<String>();
Date beginDate = parseDate(strBeginDate);
Date endDate = parseDate(strEndDate);
String beginFormat = formatDate(beginDate, pattern);
String endFormat = formatDate(endDate, pattern);
ret.add(beginFormat);
while (!beginFormat.equals(endFormat)) {
    beginDate = addMonth(beginDate, 1);
...
String[]getMonths()
Returns all months in a string array.
return new DateFormatSymbols().getMonths();
String[]getMonths(DateFormatSymbols symbols)
get Months
String[] months = new String[12];
String[] localeMonths = symbols.getMonths();
months[0] = localeMonths[Calendar.JANUARY];
months[1] = localeMonths[Calendar.FEBRUARY];
months[2] = localeMonths[Calendar.MARCH];
months[3] = localeMonths[Calendar.APRIL];
months[4] = localeMonths[Calendar.MAY];
months[5] = localeMonths[Calendar.JUNE];
...
intgetMonthSpace(Date date)
get Month Space
SimpleDateFormat df = new SimpleDateFormat(YYYYMMDDHHMMSS);
String sysTime = df.format(new Date());
String creTime = df.format(date);
;
int inum = 0;
int sysYear = Integer.parseInt(sysTime.substring(0, 4));
int sysMonth = Integer.parseInt(sysTime.substring(5, 7));
int creYear = Integer.parseInt(creTime.substring(0, 4));
...
StringgetMonthStartTime(int year, int month)
get Month Start Time
Calendar now = Calendar.getInstance(Locale.CHINA);
if (year > 2014) {
    now.set(Calendar.YEAR, year);
now.set(Calendar.MONTH, month - 1);
now.set(Calendar.DAY_OF_MONTH, 1);
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
...
StringgetMonthString(Date date)
get Month String
DateFormat dateFormat = createNewDateFormat(monthFormat);
return formatDateString(date, dateFormat);