Java Date Time - YearMonth now(Clock clock) example








YearMonth now(Clock clock) creates the current year-month from the specified clock.

Syntax

now has the following syntax.

public static YearMonth now(Clock clock)

Example

The following example shows how to use now.

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

  }
}

The code above generates the following result.