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

StringgetYear(boolean fourDigit)
Returns the current Year as a string (e.g.
if (mCalendar == null)
    Init();
String year = mCalendar.get(Calendar.YEAR) + "";
if (year.length() == 4 && fourDigit)
    return year;
return year.substring(2);
StringgetYear(int num)
get Year
Calendar calendar = new GregorianCalendar();
int year = calendar.get(Calendar.YEAR) + num;
int month = calendar.get(Calendar.MONTH);
String yearstr = "";
if (month < 8) {
    yearstr = String.valueOf(-1) + "/" + String.valueOf(year);
} else {
    yearstr = String.valueOf(year) + "/" + String.valueOf(year + 1);
...
intgetYear(long t)
get Year
Calendar cld = Calendar.getInstance();
if (t > 0) {
    cld.setTime(new java.util.Date(t));
return cld.get(Calendar.YEAR);
DategetYearBegin(int year)
get Year Begin
Calendar ca = Calendar.getInstance();
truncate(ca);
ca.set(DAY_OF_MONTH, 1);
ca.set(MONTH, 0);
ca.set(YEAR, year);
return ca.getTime();
DategetYearFirst(int year)
get Year First
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
Date currYearFirst = calendar.getTime();
return currYearFirst;
StringgetYearFormat(String dateString)
get Year Format
int start = 0;
int to = dateString.indexOf(".");
return dateString.substring(start, to);
intgetYearFromDay(int days)
Converts the number of elapsed days from 0001/01/01 (YYYY/MM/DD) to the corresponding year.
int cycles = days / DAYS_LEAP_CYCLE;
int cycleRest = days % DAYS_LEAP_CYCLE;
int centInCycle = cycleRest / DAYS_CENTURY;
int centRest = cycleRest % DAYS_CENTURY;
centRest += DAYS_CENTURY * (centInCycle / (YEARS_LEAP_CYCLE / YEARS_CENTURY));
centInCycle -= (centInCycle / (YEARS_LEAP_CYCLE / YEARS_CENTURY));
int leapInCent = centRest / DAYS_LEAP;
int leapRest = centRest % DAYS_LEAP;
...
IntegergetYearFromISODate(String isoDate)
Method to return the year part from an iso date in either yyyy, yyyy-mm, or yyyy-mm-dd
Integer year = null;
if (isoDate.matches("\\d{4}")) { 
    year = new Integer(isoDate);
} else if (isoDate.matches("\\d{4}-\\d{2}") || isoDate.matches("\\d{4}-\\d{2}-\\d{2}")) {
    String[] sa = isoDate.split("-");
    year = new Integer(sa[0]);
} else if (isoDate.matches("\\d{8}")) { 
    String stringYear = isoDate.substring(0, 4);
...
intgetYearFromTimestamp(long ms)
get Year From Timestamp
if (ms < 0)
    throw new NumberFormatException("argument must be positive");
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
cal.setTimeInMillis(ms);
return cal.get(Calendar.YEAR);
intgetYearFromWeekCode(String weekCode)
get Year From Week Code
return Integer.parseInt(weekCode.substring(0, 4));