YearMonth

Description

A YearMonth represents a valid combination of a year and a month, for example, 2012-05, 2013-09, etc.

Example

The following code shows how to create YearMonth objects and perform some basic operatioins on them.


import java.time.Month;
import java.time.YearMonth;
/*  ww  w  .  j a v a 2 s  .  c  om*/
public class Main {

  public static void main(String[] args) {
    YearMonth ym1 = YearMonth.of(2014, Month.JUNE);  

    int monthLen = ym1.lengthOfMonth(); 
    System.out.println(monthLen);

    int yearLen  = ym1.lengthOfYear();
    System.out.println(yearLen);
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    Tutorial »




Java Date Time Tutorial