java.time.LocalDate.getMonthValue() 方法示例



說明

java.time.LocalDate.getMonthValue() 方法獲取 1 到 12 之間的年中月份欄位。

宣告

以下是 java.time.LocalDate.getMonthValue() 方法的宣告。

public int getMonthValue()

返回值

年中月份,從 1 到 12。

示例

以下示例顯示了 java.time.LocalDate.getMonthValue() 方法的使用。

package com.tutorialspoint;

import java.time.LocalDate;

public class LocalDateDemo {
   public static void main(String[] args) {
	  
      LocalDate date = LocalDate.parse("2017-02-03");
      System.out.println(date.getMonthValue());  
   }
}

讓我們編譯並執行上述程式,這將產生以下結果 -

2
廣告
© . All rights reserved.