Java Utililty Methods Year From

List of utility methods to do Year From

Description

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

Method

StringgetYearFromYM(String ym)
get Year From YM
if (ym == null || ym.length() != DEFAULT_DATE_YM_FORMAT.length()) {
    return null;
return ym.substring(0, 4);
StringgetYearMonth(String day)
get Year Month
if (day == null)
    return "";
if (day.length() < 8)
    return "";
int n = day.lastIndexOf("-");
return day.substring(0, n);
String[]getYearMonthArray(Integer yearMonth)
get Year Month Array
String[] rv = new String[2];
rv[0] = String.valueOf(yearMonth / 12);
rv[1] = String.format("%02d", yearMonth % 12 + 1);
return rv;
intgetYearMonthDays(int year, int month)
get Year Month Days
int days = 31;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
...
intgetYearNumberofdays(String date)
get Year Numberofdays
int year = Integer.parseInt(date.split("-")[0]);
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    return 366;
return 365;
intgetYearOfDayMark(int day)
get Year Of Day Mark
return day / 10000;
intgetYearOfPreYearWeek(int year, int week)
get Year Of Pre Year Week
return week == 1 ? year - 1 : year;
IntegergetYearOfTime(Long time)
get Year Of Time
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
return cal.get(Calendar.YEAR);
ListgetYears(Integer limit)
get Years
List<Integer> years = new ArrayList<Integer>();
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int count = year + limit;
int i = (year);
for (; i < count; i++) {
    years.add(i);
return years;
Listgetyears(List numberList)
getyears
List<Integer> returnList = new ArrayList<Integer>();
Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int size = numberList.size();
for (int i = 0; i < size; i++) {
    Long number = (Long) numberList.get(i);
    if ((number > 1980) && (number <= year)) {
        returnList.add(Integer.parseInt(numberList.get(i).toString()));
...