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



描述

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

宣告

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

public int getMonthValue()

返回值

年月份,從 1 到 12。

示例

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

package com.tutorialspoint;

import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {
 
      MonthDay date = MonthDay.parse("--12-30");
      System.out.println(date.getMonthValue());  
   }
}

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

12
廣告
© . All rights reserved.