java.time.LocalDateTime.getMonthValue() 的示例方法



說明

java.time.LocalDateTime.getMonthValue() 方法從 1 到 12 獲取與年相關的 field。

宣告

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

public int getMonthValue()

返回值

從 1 到 12 的與年相關的 field。

示例

以下示例展示了 java.time.LocalDateTime.getMonthValue() 方法的用法。

package com.tutorialspoint;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.parse("2017-02-03T12:30:30");
      System.out.println(date.getMonthValue());  
   }
}

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

2
廣告
© . All rights reserved.