Java中MonthDay类的getDayOfMonth()方法获取day-of-month字段。
用法:
public int getDayOfMonth()
参数:此方法不接受任何参数。
返回值:该函数从1到31返回day-of-month。
以下示例程序旨在说明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
最后
以上就是沉静蜡烛最近收集整理的关于java day of month_Java MonthDay getDayOfMonth()用法及代码示例的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复