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

DateaddDate(Calendar cal, int year, int month, int day)
add Date
int y = cal.get(Calendar.YEAR);
int m = cal.get(Calendar.MONTH);
int d = cal.get(Calendar.DATE);
cal.set(y + year, m + month, d + day);
return cal.getTime();
intAddMonths(int yearMonth, int interval)
Add Months
int result = 0;
java.util.Date ym;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
ym = sdf.parse(String.valueOf(yearMonth));
Calendar cal = Calendar.getInstance();
cal.setTime(ym);
cal.add(Calendar.MONTH, interval);
result = Integer.parseInt(sdf.format(cal.getTime()));
...
DatecalculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour, int incrementMin, int incrementSec)
calculator Date
Calendar c = Calendar.getInstance();
if (incrementYear != 0) {
    c.add(Calendar.YEAR, incrementYear);
if (incrementMonth != 0) {
    c.add(Calendar.MONTH, incrementMonth);
if (incrementDay != 0) {
...
CalendarcreateCalendar(int year, int month, int date, int hour, int minute, int second)
create Calendar
final Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ENGLISH);
c.clear();
c.set(year, month, date, hour, minute, second);
return c;
DatecreateDate(final int year, final int month, final int day, final int hour, final int minutes, final int seconds, final int miliseconds)
create Date
final Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, day);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
calendar.set(Calendar.MILLISECOND, miliseconds);
...
DatecreateDate(int year, int month, int day)
create Date
Calendar c = new GregorianCalendar();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, day);
return startOfDay(c.getTime());
DatecreateDate(int year, int month, int dayOfMonth)
create Date
CALENDAR.set(Calendar.YEAR, year);
CALENDAR.set(Calendar.MONTH, month);
CALENDAR.set(Calendar.DAY_OF_MONTH, dayOfMonth);
return CALENDAR.getTime();
Datedate(final int year, final int month, final int day, final int hour, final int minute, final int second)
date
return new GregorianCalendar(year, month - 1, day, hour, minute, second).getTime();
Datedate(int year, int month, int day)
Convenience method to create a new date
return date(year, month, day, 0, 0, 0);
longDate2Long(int year, int month, int date)
Date Long
Calendar cld = Calendar.getInstance();
month = month - 1;
cld.set(year, month, date);
return cld.getTime().getTime();