Java Utililty Methods Day of Week

List of utility methods to do Day of Week

Description

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

Method

StringgetDayOfWeekAsString(String sYear, String sMonth, String sDay)
get Day Of Week As String
Calendar cd = new GregorianCalendar(Integer.parseInt(sYear), Integer.parseInt(sMonth) - 1,
        Integer.parseInt(sDay));
SimpleDateFormat sdf = new SimpleDateFormat("EEE", Locale.KOREA); 
Date d1 = cd.getTime();
return sdf.format(d1);
intgetDayofWeekByDay(String year, String month, String day)
get Dayof Week By Day
Calendar calendar = Calendar.getInstance(Locale.UK);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
calendar.set(Calendar.YEAR, Integer.parseInt(year));
calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1);
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
long milltimes = calendar.getTimeInMillis();
calendar.setTimeInMillis(milltimes);
...
DategetDayofWeekForContainedDate(Date dt, DayOfWeek dow)
Find the day of week within the week that the dt is part of.
LocalDate dtLocalDate = dateToSystemLocalDate(dt);
LocalDateTime dtLocalDateTime = dtLocalDate.atStartOfDay();
dtLocalDate = dtLocalDateTime.toLocalDate();
Date retDate;
if (isDayOfWeek(dtLocalDate, dow)) {
    retDate = localDateToSystemAdjustedStartOfDayDate(dtLocalDate);
} else {
    int dtVal = dtLocalDateTime.getDayOfWeek().getValue();
...
IntegergetDaysByWeek(Integer month, Integer year, Integer week)
get Days By Week
Integer num = null;
Calendar c = Calendar.getInstance();
c.set(year, month - 1, 1);
int mountDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
num = mountDay / 7;
int yu = mountDay % 7;
for (int i = 1; i <= yu; i++) {
    c.set(Calendar.DAY_OF_MONTH, i);
...
MapgetDaysByWeek2(Integer month, Integer year, Integer begin)
get Days By Week
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Calendar c = Calendar.getInstance();
c.set(year, month - 1, 1);
for (int i = 1; i < begin; i++) {
    c.set(Calendar.DAY_OF_MONTH, i);
    if (1 == c.get(Calendar.DAY_OF_WEEK)) {
        Integer value = map.get(1) == null ? 0 : map.get(1);
        map.put(1, value + 1);
...
DategetDayWeekDate(String dateStr)
get Day Week Date
try {
    return getDateFromString(dateStr, "dd MMM yyyy' 'HH:mm");
} catch (Exception ex) {
    Calendar resultCalendar = Calendar.getInstance();
    resultCalendar.setTime(getDateFromString(dateStr, "EEE dd MMM' 'HH:mm"));
    resultCalendar.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    return resultCalendar.getTime();
StringgetDayWeekDateStr(Date date)
get Day Week Date Str
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
if (Calendar.getInstance().get(Calendar.YEAR) != calendar.get(Calendar.YEAR))
    return getDateStr(date, "dd MMM yyyy' 'HH:mm");
else
    return getDateStr(date, "EEE dd MMM' 'HH:mm");
DategetEndOfWeek(Date date)
Gets the end of week.
return getWeek(date)[1];
DategetFirstDayOfLastWeek(Date date)
get First Day Of Last Week
Calendar c = Calendar.getInstance();
c.setTimeInMillis(date.getTime() - 604800000L);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date lastWeekDate = c.getTime();
c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
...
intgetFirstDayOfWeek(int year, int week)
get First Day Of Week
Calendar c = Calendar.getInstance(Locale.US);
c.set(year, 1, 1, 0, 0, 0);
c.set(Calendar.WEEK_OF_YEAR, week);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
int dayOfYear = c.get(Calendar.DAY_OF_YEAR);
if (c.get(Calendar.YEAR) < year) {
    Calendar x = Calendar.getInstance(Locale.US);
    x.set(c.get(Calendar.YEAR), 11, 31, 0, 0, 0);
...