Java Utililty Methods Year Get

List of utility methods to do Year Get

Description

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

Method

StringgetDateOneYearFromNow()
get Date One Year From Now
String day = "", month = "", year = "";
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 1);
int mm = (cal.get(Calendar.MONTH) + 1);
int dd = cal.get(Calendar.DATE);
year = "" + cal.get(Calendar.YEAR);
if (mm < 10)
    month = "0";
...
longgetDaysFromYearZero(Calendar date)
get Days From Year Zero
return ((date.get(Calendar.YEAR) * 365) - 365) + date.get(Calendar.DAY_OF_YEAR);
StringgetFewYearsTime(String date, int year)
get Few Years Time
int years = Integer.parseInt(date.split("-")[0]);
int month = Integer.parseInt(date.split("-")[1]);
int data = Integer.parseInt(date.split("-")[2]);
Calendar calendar = new GregorianCalendar(years, month - 1, data);
calendar.add(Calendar.YEAR, year);
Date d = calendar.getTime();
return new SimpleDateFormat("yyyy-MM-dd").format(d);
DategetHalfYearEndDate(Date date)
get Half Year End Date
try {
    String strDate = "";
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String format2 = format.format(date);
    String[] split = format2.split("-");
    String year = split[0];
    String month = split[1];
    int parseInt = Integer.parseInt(month);
...
DategetLastDayOfYear(Date date)
Function: get LastDay
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
Calendar lastDay = new GregorianCalendar(year, Calendar.DECEMBER, 31);
return lastDay.getTime();
intgetNextYear()
get Next Year
return new GregorianCalendar().get(Calendar.YEAR) + 1;
DategetNextYearFirst()
get Next Year First
Calendar currCal = Calendar.getInstance();
int currentYear = currCal.get(Calendar.YEAR);
return getYearFirst(currentYear + 1);
String[]getNextYearMonthStr()
get Next Year Month Str
String ret[] = new String[12];
Calendar c = Calendar.getInstance();
int nextYear = c.get(Calendar.YEAR) + 1;
for (int i = 0; i < monthStrArray.length; i++) {
    ret[i] = nextYear + monthStrArray[i];
return ret;
ListgetOfflimitDates(int year)
get Offlimit Dates
List<Date> offlimitDates = new ArrayList<>();
Calendar baseCalendar = GregorianCalendar.getInstance();
baseCalendar.clear();
baseCalendar.set(year, Calendar.JANUARY, 1);
offlimitDates.add(offsetForWeekend(baseCalendar));
baseCalendar.set(year, Calendar.JULY, 4);
offlimitDates.add(offsetForWeekend(baseCalendar));
baseCalendar.set(year, Calendar.DECEMBER, 25);
...
GregorianCalendargetRandomDate(int firstYar, int lastYear)
get Random Date
int month, day, year, maxday;
year = getRandomInt(firstYar, lastYear);
month = getRandomInt(0, 11);
maxday = 31;
if (month == 3 | month == 5 | month == 8 | month == 10) {
    maxday = 30;
} else if (month == 1) {
    maxday = 28;
...