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.