public enum DayOfWeek extends Enum<DayOfWeek> implements Calendrical
DayOfWeek is an enum representing the 7 days of the week -
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendrical framework requires date-time fields to have an int value.
The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
It is recommended that applications use the enum rather than the int value
to ensure code clarity.
Do not use ordinal() to obtain the numeric representation of DayOfWeek.
Use getValue() instead.
This enum represents a common concept that is found in many calendar systems.
As such, this enum may be used by any calendar system that has the day-of-week
concept with a seven day week where the names are equivalent to those defined.
Note that the implementation of DateTimeFieldRule for day-of-week may
vary by calendar system.
DayOfWeek is an immutable and thread-safe enum.
| Enum Constant and Description |
|---|
FRIDAY
The singleton instance for the day-of-week of Friday.
|
MONDAY
The singleton instance for the day-of-week of Monday.
|
SATURDAY
The singleton instance for the day-of-week of Saturday.
|
SUNDAY
The singleton instance for the day-of-week of Sunday.
|
THURSDAY
The singleton instance for the day-of-week of Thursday.
|
TUESDAY
The singleton instance for the day-of-week of Tuesday.
|
WEDNESDAY
The singleton instance for the day-of-week of Wednesday.
|
| Modifier and Type | Method and Description |
|---|---|
static DayOfWeek |
firstDayOfWeekFor(Locale locale)
Returns the
DayOfWeek instance that corresponds to the first
day-of-week for a given locale. |
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
String |
getShortText(Locale locale)
Gets the short textual representation of this day-of-week, such as 'Mon' or 'Fri'.
|
String |
getText(Locale locale)
Gets the full textual representation of this day-of-week, such as 'Monday' or 'Friday'.
|
int |
getValue()
Gets the day-of-week
int value. |
boolean |
isFriday()
Is this instance representing Friday.
|
boolean |
isMonday()
Is this instance representing Monday.
|
boolean |
isSaturday()
Is this instance representing Saturday.
|
boolean |
isSunday()
Is this instance representing Sunday.
|
boolean |
isThursday()
Is this instance representing Thursday.
|
boolean |
isTuesday()
Is this instance representing Tuesday.
|
boolean |
isWednesday()
Is this instance representing Wednesday.
|
DayOfWeek |
next()
Gets the next day-of-week.
|
static DayOfWeek |
of(int dayOfWeek)
Obtains an instance of
DayOfWeek from an int value. |
DayOfWeek |
previous()
Gets the previous day-of-week.
|
DayOfWeek |
roll(int days)
Rolls the day-of-week, adding the specified number of days.
|
static DayOfWeek |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static DayOfWeek[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final DayOfWeek MONDAY
1.public static final DayOfWeek TUESDAY
2.public static final DayOfWeek WEDNESDAY
3.public static final DayOfWeek THURSDAY
4.public static final DayOfWeek FRIDAY
5.public static final DayOfWeek SATURDAY
6.public static final DayOfWeek SUNDAY
7.public static DayOfWeek[] values()
for (DayOfWeek c : DayOfWeek.values()) System.out.println(c);
public static DayOfWeek valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static DayOfWeek of(int dayOfWeek)
DayOfWeek from an int value.
DayOfWeek is an enum representing the 7 days of the week.
This factory allows the enum to be obtained from the int value.
The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
An exception is thrown if the value is invalid. The exception uses the
ISOChronology day-of-week rule to indicate the failed rule.
dayOfWeek - the day-of-week to represent, from 1 (Monday) to 7 (Sunday)IllegalCalendarFieldValueException - if the day-of-week is invalidpublic static DayOfWeek firstDayOfWeekFor(Locale locale)
DayOfWeek instance that corresponds to the first
day-of-week for a given locale.
If there is no information for a locale, MONDAY is returned.
locale - the locale to use, not nullpublic int getValue()
int value.
The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
public <T> T get(CalendricalRule<T> rule)
This returns the one of the day-of-week values if the type of the rule
is DayOfWeek. Other rules will return null.
get in interface Calendricalrule - the rule to use, not nullpublic String getShortText(Locale locale)
This method is notionally specific to ISOChronology as it uses
the day-of-week rule to obtain the text. However, it is expected that
the text will be equivalent for all day-of-week rules, thus this aspect
of the implementation should be irrelevant to applications.
If there is no textual mapping for the locale, then the ISO-8601
value is returned as per Integer.toString().
locale - the locale to use, not nullpublic String getText(Locale locale)
This method is notionally specific to ISOChronology as it uses
the day-of-week rule to obtain the text. However, it is expected that
the text will be equivalent for all day-of-week rules, thus this aspect
of the implementation should be irrelevant to applications.
If there is no textual mapping for the locale, then the ISO-8601
value is returned as per Integer.toString().
locale - the locale to use, not nullpublic boolean isMonday()
public boolean isTuesday()
public boolean isWednesday()
public boolean isThursday()
public boolean isFriday()
public boolean isSaturday()
public boolean isSunday()
public DayOfWeek next()
This calculates based on the time-line, thus it rolls around the end of the week. The next day after Sunday is Monday.
public DayOfWeek previous()
This calculates based on the time-line, thus it rolls around the end of the week. The previous day before Monday is Sunday.
public DayOfWeek roll(int days)
This calculates based on the time-line, thus it rolls around the end of the week from Sunday to Monday. The days to roll by may be negative.
This instance is immutable and unaffected by this method call.
days - the days to roll by, positive or negativeCopyright © 2024. All rights reserved.