Java Utililty Methods Week Day

List of utility methods to do Week Day

Description

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

Method

DategetWeekDay(String dateString, int weekDay)
return date's weekday value of specified string value in format: yyyy-MM-dd Date first = DateUtil.getMonday(today,Calendar.SUNDAY); Date last = DateUtil.getMonday(today,Calendar.SATURDAY);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
    date = simpleDateFormat.parse(dateString);
} catch (Exception e) {
    e.printStackTrace();
Calendar calendar = Calendar.getInstance();
...
intgetWeekDay(String str)
get Week Day
if (str.length() < 3) {
    return -1;
if (str.regionMatches(true, 0, "sunday", 0, str.length())) {
    return Calendar.SUNDAY;
} else if (str.regionMatches(true, 0, "monday", 0, str.length())) {
    return Calendar.MONDAY;
} else if (str.regionMatches(true, 0, "tuesday", 0, str.length())) {
...
StringgetWeekDayByDate(Date date)
get Week Day By Date
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
String week = sdf.format(date);
return week;
StringgetWeekDayCN()
get Week Day CN
sdf.applyPattern("EEEE");
return sdf.format(new Date());
StringgetWeekdayForInt(int value)
Return a string name for the contants from Calendar.
switch (value) {
case Calendar.MONDAY:
    return "Monday";
case Calendar.TUESDAY:
    return "Tuesday";
case Calendar.WEDNESDAY:
    return "Wednesday";
case Calendar.THURSDAY:
...
StringgetWeekdayName(Date date)
get Weekday Name
return dfWeekday.format(date);
String[]getWeekdayNames()
get Weekday Names
DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
String[] dayNames = symbols.getWeekdays();
return Arrays.copyOfRange(dayNames, 1, 7);
String[]getWeekdayNames(Locale locale)
Get an array of weekday names for a given locale.
SimpleDateFormat dayFormatter = new SimpleDateFormat("E", locale);
String[] weekdayName = new String[7];
GregorianCalendar cal = new GregorianCalendar(2005, java.util.Calendar.JANUARY, 1);
int currentWeekday = cal.get(java.util.Calendar.DAY_OF_WEEK);
int daysUntilNextSunday = java.util.Calendar.SATURDAY - currentWeekday + 1;
cal.add(java.util.Calendar.DAY_OF_MONTH, daysUntilNextSunday);
for (int iDay = 0; iDay < 7; iDay++) {
    weekdayName[iDay] = dayFormatter.format(cal.getTime()).subSequence(0, 1).toString();
...
intgetWeekDayNUM()
get Week Day NUM
car.setTimeInMillis(System.currentTimeMillis());
return (car.get(Calendar.DAY_OF_WEEK) - 1) == 0 ? 7 : (car.get(Calendar.DAY_OF_WEEK) - 1);
intgetWeekdayOfDateTime(String datetime)
get Weekday Of Date Time
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try {
    c.setTime(df.parse(datetime));
} catch (Exception e) {
    e.printStackTrace();
int weekday = c.get(Calendar.DAY_OF_WEEK) - 1;
...