Java Utililty Methods Year Day

List of utility methods to do Year Day

Description

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

Method

StringgetCurrYearFirstDay(int year)
get Curr Year First Day
SimpleDateFormat format = new SimpleDateFormat(default_format);
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
Date currYearFirst = calendar.getTime();
return format.format(currYearFirst);
StringgetFirstDay4CurrentYear()
get First Day Current Year
SimpleDateFormat df = new SimpleDateFormat("yyyy");
String todayAsString = df.format(new Date());
todayAsString = todayAsString + "-01-01";
return todayAsString;
StringgetFirstDayOfThisYear()
get First Day Of This Year
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_YEAR, 1);
Date date = new Date(calendar.getTimeInMillis());
return shortDateFormat.format(date);
DategetLastDayOfTheYear(int year)
get Last Day Of The Year
Calendar lastDayOfThisYear = Calendar.getInstance();
lastDayOfThisYear.clear();
lastDayOfThisYear.set(Calendar.YEAR, year);
lastDayOfThisYear.set(Calendar.DAY_OF_YEAR, 1);
lastDayOfThisYear.add(Calendar.YEAR, 1);
lastDayOfThisYear.add(Calendar.MILLISECOND, -1);
return lastDayOfThisYear.getTime();
DategetLastDayOfYear(int year)
get Last Day Of Year
return getEndDate(Calendar.DECEMBER, year);
DategetLastDayOfYear(int year)
get Last Day Of Year
return getLastDayOfQuarter(year, 4);
intgetTodayYear()
get Today Year
int yyyy = Integer.parseInt(dateFormat(new Date(), "yyyy"));
return yyyy;
intgetWeekNumOfYearDay(String strDate)
get Week Num Of Year Day
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = format.parse(strDate);
int iWeekNum;
calendar.setTime(curDate);
if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
    iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1;
} else {
...
DategetYearFirstDay(String date)
get Year First Day
SimpleDateFormat format = new SimpleDateFormat("yyyy");
Date d = null;
try {
    d = format.parse(date);
} catch (Exception e) {
    e.printStackTrace();
Calendar cal = Calendar.getInstance();
...
DategetYearLastDay(String dateString)
return the last day of the date's year of specified string value in format: yyyy
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
Date date = null;
try {
    date = simpleDateFormat.parse(dateString);
} catch (Exception e) {
    e.printStackTrace();
Calendar calendar = Calendar.getInstance();
...