Java中MonthDay类的getMonth()方法从时间对象获取MonthDay的实例。
用法:
public Month getMonth()
参数:此方法不接受任何参数。
返回值:该函数返回month-of-year,并且不为null。
以下示例程序旨在说明MonthDay.getMonth()方法:
示例1:
// Program to illustrate the getMonth() 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 date
System.out.println(dt1.getMonth());
}
}
输出:
DECEMBER
示例2:
// Program to illustrate the getMonth() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Parses the date
MonthDay tm1 = MonthDay.parse("--01-09");
// Uses the function
LocalDate dt1 = tm1.atYear(2016);
// Prints the date
System.out.println(dt1.getMonth());
}
}
输出:
JANUARY
最后
以上就是精明星星最近收集整理的关于java month_Java MonthDay getMonth()用法及代码示例的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复