static YearMonth now(ZoneId zone)
描述 (Description)
java.time.YearMonth.now(ZoneId zone)方法从指定时区中的系统时钟获取当前年月。
声明 (Declaration)
以下是java.time.YearMonth.now(ZoneId zone)方法的声明。
public static YearMonth now(ZoneId zone)
参数 (Parameters)
zone - 要使用的区域ID,不为null。
返回值 (Return Value)
使用系统时钟的当前年月,不为空。
例子 (Example)
以下示例显示了java.time.YearMonth.now(ZoneId zone)方法的用法。
package com.iowiki;
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