Java Utililty Methods Month of Year

List of utility methods to do Month of Year

Description

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

Method

Calendarcreate(final int year, final int month, final int day)
create
return create(year, month, day, 0, 0, 0);
Datecreate(int year, int month, int day)
Create a (truncated) date object from year, month, day.
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
validate(year, month, day, calendar);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
...
Datecreate(int year, int month, int day, int hour, int minute, int second)
create
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, day, hour, minute, second);
calendar.set(Calendar.MILLISECOND, 0);
Date expected = calendar.getTime();
return expected;
StringcreateKey(int instance, int year, int month, int day, int hour, int min, int sec, int milli, String uuid, boolean rolling)
Create a key from all of the parts.
String roll = rolling ? ROLLING : "";
return String.format(KEY_TEMPLATE, getInstancePrefix(instance), getDateString(year, month, day), hour, min,
        sec, milli, uuid, roll);
longcreateTimestamp(int year, int month, int day, int hour, int minutes, int seconds)
create Timestamp
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
...
intcurrentYearMonth()
current Year Month
Calendar c = Calendar.getInstance();
return formatDateIntValue(c.getTime(), YYYYMMINTFORMAT);
intdayOfYear(int year, int month, int day)
day Of Year
return getCalendar(year, month, day).get(Calendar.DAY_OF_YEAR);
intdayOfYear(int year, int month, int day)
day Of Year
Calendar c = Calendar.getInstance();
c.set(year, month - 1, day);
return c.get(c.DAY_OF_YEAR);
intdaysInMonth(final int month, final int year)
days In Month
final Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
return calendar.getActualMaximum(Calendar.DATE);
intdaysInMonth(final int year, final int month)
Get the number of days in that month.
Calendar cal = Calendar.getInstance();
cal.set(year, month, 1);
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);