109
Java MonthDay Class
Java MonthDay class is an immutable date-time object that represents the combination of a month and day-of-month. It inherits Object class and implements the Comparable interface.
JJava MonthDay Class Declaration
Let’s see the declaration of java.time.MonthDay class.
Methods of Java MonthDay Class
Method | Description |
---|---|
LocalDate atYear(int year) | It is used to combine this month-day with a year to create a LocalDate. |
String format(DateTimeFormatter formatter) | It is used to format this month-day using the specified formatter. |
int get(TemporalField field) | It is used to get the value of the specified field from this month-day as an int. |
boolean isValidYear(int year) | It is used to check if the year is valid for this month-day. |
static MonthDay now() | It is used to obtain the current month-day from the system clock in the default time-zone. |
static MonthDay of(int month, int dayOfMonth) | It is used to obtain an instance of MonthDay. |
ValueRange range(TemporalField field) | It is used to get the range of valid values for the specified field. |
int getDayOfMonth() | It gets the day-of-month field. |
Month getMonth() | It gets the month-of-year field using the Month enum. |
int getMonthValue() | It gets the month-of-year field from 1 to 12. |
int hashCode() | It returns a hash code for this month-day. |
boolean isAfter(MonthDay other) | It checks if this month-day is after the specified month-day. |
static MonthDay now() | It obtains the current month-day from the system clock in the default time-zone. |
static MonthDay now(Clock clock) | It obtains the current month-day from the specified clock. |
static MonthDay of(int month, int dayOfMonth) | It obtains an instance of MonthDay. |
R query(TemporalQuery query) | It queries this month-day using the specified query. |
ValueRange range(TemporalField field) | It gets the range of valid values for the specified field. |
String toString() | It outputs this month-day as a String, such as -12-03. |
MonthDay with(Month month) | It returns a copy of this MonthDay with the month-of-year altered. |
MonthDay withDayOfMonth(int dayOfMonth) | It returns a copy of this MonthDay with the day-of-month altered. |
MonthDay withMonth(int month) | It returns a copy of this MonthDay with the month-of-year altered. |
Java MonthDay Class Example
MonthDayExample1.java
Output:
1994-01-17
Java MonthDay Class Example: isValidYear()
MonthDayExample2.java
Output:
true
Java MonthDay Class Example: get()
MonthDayExample3.java
Output:
1
Java MonthDay Class Example: range()
MonthDayExample4.java
Output:
1 - 12 1 - 31
Next TopicJava OffsetTime