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

StringgetYear(String strDate)
get Year
String year = "";
if (strDate != null && !strDate.equals("")) {
    strDate = strDate.trim();
    year = getElement(strDate.split("-"), 0);
return year;
DategetYear(String string)
Returns the year given a string in format yyyy.
if (string == null) {
    return null;
Date date = null;
try {
    date = (new SimpleDateFormat("yyyy").parse(string));
} catch (ParseException ex) {
    return null;
...
StringgetYear(String tempdat, Locale locale)
This method parses the @param String tempdat, according to a specified format style determined by the @param Locale locale to a Date.
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale);
Date d = df.parse(tempdat, new ParsePosition(0));
Calendar cal_date = new GregorianCalendar();
cal_date.setTime(d);
int jahr = 0;
jahr = cal_date.get(Calendar.YEAR);
String jahrstr = String.valueOf(jahr);
return jahrstr;
...
StringgetYear(String[] contents)
get Year
return contents[0];
intgetYearCount(String from, String to)
get Year Count
return getYearCount(from, to, DATE_FORMAT.toPattern());
DategetYearEnd(Date date)
get Year End
String newDateStr = FormatDate(date, "yyyy") + "-12-31";
return stringToDateShort(newDateStr);
intgetYearForDate(String dateToCheck, String pattern)
Parses a string into a date.
if (isDateValid(dateToCheck, pattern) && dateToCheck.length() == pattern.length()) {
    int index = pattern.indexOf("yyyy"); 
    if (index == -1) {
        return (-1);
    String year_str = dateToCheck.substring(index, index + 4);
    int year = -1;
    try {
...
ArrayListgetYearList(int years)
get Year List
ArrayList<String> yearList = new ArrayList<>(years);
int startYear = Calendar.getInstance().get(Calendar.YEAR);
for (int i = 0; i < years; i++)
    yearList.add(Integer.toString(startYear + i));
return yearList;
StringgetYearLongDesc(Date year)
This method is used for getting year long description
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy");
return sdf.format(year);
ListgetYearlyIntervals(Date start, Date end)
get Yearly Intervals
List<Date> intervals = new ArrayList<Date>();
GregorianCalendar c = new GregorianCalendar();
c.setTime(start);
int startYear = c.get(Calendar.YEAR);
int year = startYear;
intervals.add(start);
while (true) {
    year++;
...