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

DategetStartMonth(int year, int month)
get Start Month
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, 1);
return getStartDate(calendar.getTime());
CalendargetTheLastDayOfTheMonth(int year, int month)
get The Last Day Of The Month
Calendar cal = new GregorianCalendar();
cal.set(year, month, 1);
return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
        cal.get(Calendar.DAY_OF_MONTH) - 1);
StringgetThisYearMonth()
get This Year Month
return getYearMonth(new Date());
intgetThisYearMonth()
get This Year Month
Calendar today = Calendar.getInstance();
return (today.get(Calendar.YEAR)) * 100 + today.get(Calendar.MONTH) + 1;
longgetTimeByYearMonth(String yearMonth, String timeZone)
get Time By Year Month
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    Date date = simpleDateFormat.parse(yearMonth + "-01 00:00:00");
    return date.getTime();
} catch (ParseException ex) {
    System.out.println("Exception " + ex);
return 0L;
StringgetYearAndMonth()
get Year And Month
return toString(new Date(), PATTERN_YYYYMM);
longgetYearMonth()
get Year Month
return getYearMonth(new Date());
StringgetYearMonth()
get Year Month
String yearMonth = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
yearMonth = sdf.format(new java.util.Date());
return yearMonth;
StringgetYearMonth(Calendar sDate)
get Year Month
if (sDate == null)
    return "";
return (new java.text.SimpleDateFormat("yyyy-MM")).format(sDate.getTime());
StringgetYearMonth(Date date)
get Year Month
if (null == date) {
    return null;
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyyMM");
return yearFormat.format(date);