java.time.YearMonth.now() 方法示例



描述

java.time.YearMonth.now(ZoneId zone) 方法從所指定時區中的系統時鐘獲取當前年月份。

宣告

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

public static YearMonth now(ZoneId zone)

引數

zone − 要使用的時區 ID,非空。

返回值

使用系統時鐘獲取的當前年月份,非空。

示例

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

package com.tutorialspoint;

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
廣告
© . All rights reserved.