CodesJava

Easy learning with example program codes

Java Month enum


Java Month is an enum which represents the 12 months of the year.

Java Month enum methods

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.

Example

package com.codesjava;
 
import java.time.LocalDate;
import java.time.Month;
 
public class TestExample {
	public static void main(String args[]){
	    Month month = Month.from(LocalDate.now());  
	    System.out.println(month.getValue());  
	    System.out.println(month.name());  
	    System.out.println(month.length(true));
	    //plus() method
	    System.out.println(month.plus(2));  
	    //minus() method
	    System.out.println(month.minus(1));  
	}  
}

Output

4
APRIL
30
JUNE
MARCH
Posted in Date   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki