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

StringgetOntologyURIBase(String defaultBase, boolean appendYear, boolean appendMonth, boolean appendDay)
get Ontology URI Base
if (defaultBase != null && defaultBase.trim().length() > 0) {
    if (defaultBase.endsWith("/") == false) {
        defaultBase += "/";
    if (appendYear) {
        int year = Calendar.getInstance().get(Calendar.YEAR);
        defaultBase += year + "/";
        if (appendMonth) {
...
StringgetPreviousDateStringByMonth(int months)
get Previous Date String By Month
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -months);
return toDateString(calendar);
int[]getPreviousDay(int year, int month, int day, int days)
get Previous Day
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, day);
long longDate = (calendar.getTime()).getTime() - (1000 * 60 * 60 * 24 * days);
java.util.Date date = new java.util.Date(longDate);
calendar.setTime(date);
int[] rtn = new int[3];
rtn[0] = calendar.get(Calendar.YEAR);
rtn[1] = calendar.get(Calendar.MONTH) + 1;
...
StringgetPrevMonth(String divisionDate, int day, String outputFormat)
get Prev Month
Calendar cal = Calendar.getInstance();
cal.set(cal.YEAR, Integer.parseInt(divisionDate.substring(0, 4)));
cal.set(cal.MONTH, Integer.parseInt(divisionDate.substring(4, 6)) - 1);
cal.set(cal.DATE, Integer.parseInt(divisionDate.substring(6, 8)));
cal.add(cal.MONTH, day);
Locale locale = new Locale("KOREAN", "KOREA");
SimpleDateFormat formatter = new SimpleDateFormat(outputFormat, locale);
return formatter.format(cal.getTime());
...
StringgetPreYearMonth()
get Pre Year Month
int year = getCurrentYear();
int month = getCurrentMonth() - 1;
String yearMonth = "";
if (month == 1) {
    year = year - 1;
    month = 12;
if (month >= 10) {
...
intgetSecondsOfMonth(int year, int month)
get Seconds Of Month
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, 1, 0, 0, 0);
Calendar calendarNextMonth = (Calendar) calendar.clone();
calendarNextMonth.add(Calendar.MONTH, 1);
return new Long((calendarNextMonth.getTimeInMillis() - calendar.getTimeInMillis()) / 1000).intValue();
Calendar[]getStartAndEndOfMonth(int month, int year)
get Start And End Of Month
Calendar startDate = Calendar.getInstance();
startDate.set(year, month, 1, 0, 0);
Calendar endDate = Calendar.getInstance();
int days = getDaysInMonth(month, year);
endDate.set(year, month, days, 23, 59);
return new Calendar[] { startDate, endDate };
StringgetStrDayOfWeek(int _year, int _month, int _day)
get Str Day Of Week
int dayofweek = getDayOfWeek(_year, _month, _day);
String res;
switch (dayofweek) {
case 1:
    res = "Sun";
    break;
case 2:
    res = "Mon";
...
CalendargetThisMonth(int year, int monthIndex)
get This Month
Calendar thisMonth = Calendar.getInstance();
if (year > 1900)
    thisMonth.set(Calendar.YEAR, year);
else
    thisMonth.set(Calendar.YEAR, 1901);
if (monthIndex >= 0 && monthIndex < 12)
    thisMonth.set(Calendar.MONTH, monthIndex);
else
...
DategetTime(int year, int month, int day)
get Time
Calendar date = Calendar.getInstance();
date.set(year, month, day, 0, 0, 0);
date.set(Calendar.MILLISECOND, 0);
return date.getTime();