MonthDay 在 Java 中的 getMonth 方法
可以使用 Java 中 MonthDay 類中的 getMonth() 方法獲取特定 MonthDay 的月名稱。此方法不需要引數,它返回年中月份的名稱。
演示此功能的一個程式如下所示
示例
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.getMonth());
}
}輸出
The MonthDay is: --02-22 The month is: FEBRUARY
現在讓我們瞭解一下上述程式。
首先顯示 MonthDay。然後使用 getMonth() 方法顯示 MonthDay 的月份名稱。一個演示此功能的程式碼片段如下所示
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The month is: " + md.getMonth());
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP