java.time.YearMonth.now(ZoneId zone)方法

java.time.YearMonth.now(ZoneId zone)方法从指定时区中的系统时钟获取当前年月。

声明

以下是java.time.YearMonth.now(ZoneId zone)方法的声明。

public static YearMonth now(ZoneId zone)

参数

  • zone - 要使用的区域ID,不为null

返回值

使用系统时钟的当前年月,不为null

例子

以下示例显示了java.time.YearMonth.now(ZoneId zone)方法的用法。

package com.zaixian;

import java.time.YearMonth;
import java.time.ZoneId;

public class YearMonthDemo {
   public static void main(String[] args) {

      YearMonth date = YearMonth.now(ZoneId.systemDefault());
      System.out.println(date);  
   }
}

编译并运行上面的程序,这将产生以下结果 -

2017-03

上一篇: java.time.YearMonth类 下一篇: java.time.ZonedDateTime类