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類