Java Utililty Methods Calendar Year

List of utility methods to do Calendar Year

Description

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

Method

CalendargetStartOfWeekCalendar(final int year, final int weekOfYear, final Locale locale)
get Start Of Week Calendar
final Calendar cal = createCalendarInstance(locale);
cal.clear();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.WEEK_OF_YEAR, weekOfYear);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
...
CalendargetValidCalendar(int year, int month, int day)
Validate the actual date of the given date elements and returns a calendar instance based on the given date elements.
return getValidCalendar(year, month, day, 0, 0, 0);
StringgetWeekOfYear(Calendar currentDate)
Method getWeekOfYear.
int temp = 0;
String result = "";
temp = currentDate.get(Calendar.WEEK_OF_YEAR);
result = String.valueOf(temp).trim();
result = padString(result, false, 2, "0");
return result;
intgetWeekOfYear(int startDay, Calendar dt)
Calculates week number for given date This function is derived from JavaScript implementation used in OE
int offset = (((Math.abs(startDay - 6)) + 5) % 7); 
Calendar d3 = new GregorianCalendar(dt.get(Calendar.YEAR), dt.get(Calendar.MONTH), dt.get(Calendar.DATE), 0,
        0, 0);
d3.set(Calendar.MILLISECOND, 0);
d3.add(Calendar.DAY_OF_YEAR, offset);
double DC3 = d3.getTimeInMillis() / ms1d; 
double AWN = Math.floor(DC3 / 7); 
Calendar yCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
...
intgetWeekOfYearYear(GregorianCalendar cal)
get Week Of Year Year
int y = cal.get(Calendar.YEAR);
int m = cal.get(Calendar.MONTH) + 1 - Calendar.JANUARY;
int w = cal.get(Calendar.WEEK_OF_YEAR);
if (w == 1 && m == 12)
    return y + 1;
if (w > 50 && m == 1)
    return y - 1;
return y;
...
StringgetYear(Calendar cal)
get Year
return String.valueOf(cal.get(Calendar.YEAR));
intgetYear(Calendar calendar)
Get the year (positive or negative) from a calendar.
int year = calendar.get(Calendar.YEAR);
if (calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
    year = 1 - year;
return year;
intgetYear(Calendar calendar)
get Year
return calendar.get(Calendar.YEAR);
intgetYear(Calendar calendar)
get Year
return calendar.get(Calendar.YEAR);
intgetYear(Date date, Calendar cal)
get Year
cal.setTime(date);
return cal.get(Calendar.YEAR);