MonthDay 的 getMonthValue() 方法在 Java 中
在 Java 中的 MonthDay 類中,使用 getMonthValue() 方法可以獲取一年中的月份。此方法不需要引數,並且會返回一年中的月份,其範圍可能在 1 到 12 之間。
展示此方法的程式如下所示
範例
import java.time.*;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The month is: " + md.getMonthValue());
}
}輸出
The MonthDay is: --02-22 The month is: 2
現在讓我們瞭解一下上述程式。
首先,顯示 MonthDay。然後,使用 getMonthValue() 方法獲取一年中的月份,並顯示出來。展示此方法的程式碼段如下所示
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The month is: " + md.getMonthValue());
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP