Java Date Time - YearMonth now() example








YearMonth now() creates the current year-month from the system clock in the default time-zone.

Syntax

now has the following syntax.

public static YearMonth now()

Example

The following example shows how to use now.

import java.time.YearMonth;
//from ww w. j a va  2 s.  co  m
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    
    System.out.println(y);

  }
}

The code above generates the following result.