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



說明

java.time.YearMonth.now() 方法從系統時鐘獲取使用預設時區的當前年月。

宣告

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

public static YearMonth now()

返回值

使用系統時鐘和預設時區的當前年月,不為 null。

示例

以下示例顯示了 java.time.YearMonth.now() 方法的使用方式。

package com.tutorialspoint;

import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {
 
      YearMonth date = YearMonth.now();
      System.out.println(date);  
   }
}

讓我們編譯並執行以上程式,它將產生以下結果 −

2017-03
廣告
© . All rights reserved.