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());

更新日期: 30-7-2019

79 次浏览

开启你的 职业生涯

通过完成课程获得认证

立即开始
广告
© . All rights reserved.