MonthDay 類的 getDayOfMonth() 方法
可以使用 Java 中 MonthDay 類的 getDayOfMonth() 方法獲取特定 MonthDay 的月份天數。該方法不需要任何引數,它返回 1 至 31 範圍內的月份天數。
一個演示此程式的示例如下
示例
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 day of the month is: " + md.getDayOfMonth());
}
}輸出
The MonthDay is: --02-22 The day of the month is: 22
現在讓我們來理解以上程式。
首先顯示 MonthDay。然後使用 getDayOfMonth() 方法顯示 MonthDay 的月份天數。一個演示此程式碼段示例如下
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The day of the month is: " + md.getDayOfMonth());
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP