Java MonthDay getDayOfMonth()方法及示例

来源:这里教程网 时间:2026-02-17 20:59:01 作者:

Java MonthDay getDayOfMonth()方法及示例

Java中MonthDay类的 getDayOfMonth() 方法可以获得月的日期字段。

语法

public int getDayOfMonth()

参数。该方法不接受任何参数。

返回: 该函数返回从1到31的月日。

下面的程序说明了 MonthDay.getDayOfMonth() 方法。

程序 1 :

// Program to illustrate the getDayOfMonth() method  import java.util.*;import java.time.*;  public class GfG {    public static void main(String[] args)    {        // Parses the date        MonthDay tm1 = MonthDay.parse("--12-06");          // Uses the function        LocalDate dt1 = tm1.atYear(2018);          // Prints the day        System.out.println(dt1.getDayOfMonth());    }}

输出。

6

程序2

// Program to illustrate the getDayOfMonth() method  import java.util.*;import java.time.*;  public class GfG {    public static void main(String[] args)    {        // Parses the date        MonthDay tm1 = MonthDay.parse("--01-19");          // Uses the function        LocalDate dt1 = tm1.atYear(2018);          // Prints the day        System.out.println(dt1.getDayOfMonth());    }}

输出。

19

参考资料: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#getDayOfMonth-

相关推荐