Java Month enum In Java the Month is an enum representing the 12 months of the year. In addition with the textual enum name, every month-of-year has an int value.
Java Month enum declaration Let's see the declaration of java.time.Month.
Methods of Java Month
Method |
Description |
int getValue() |
It is used to get the month-of-year int value |
int get(TemporalField field) |
It is used to get the value of the specified field from this month-of-year as an int. |
int length(boolean leapYear) |
It is used to get the length of this month in days. |
int maxLength() |
It is used to get the maximum length of this month in days. |
int minLength() |
It is used to get the minimum length of this month in days. |
Month minus(long months) |
It is used to return the month-of-year that is the specified number of months before this one. |
Month plus(long months) |
It is used to return the month-of-year that is the specified number of quarters after this one. |
static Month of(int month) |
It is used to obtain an instance of Month from an int value. |
Java Month enum Example
Test it Now Output:
For the month of JANUARY all Sunday are:
2017-01-01
2017-01-08
2017-01-15
2017-01-22
2017-01-29
Java Month enum Example: getValue()
Test it Now Output:
Java Month enum Example: minus()
Test it Now Output:
Java Month enum Example: plus()
Test it Now Output:
Java Month enum Example: length()
Test it Now Output:
|