java.time.LocalDateTime.getMonth() 方法示例



說明

java.time.LocalDateTime.getMonth() 方法使用 Month 列舉獲取年初的月份。

宣告

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

public Month getMonth()

返回值

年初月份,非空。

示例

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

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.getMonth());  
   }
}

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

FEBRUARY
廣告
© . All rights reserved.