我是靠谱客的博主 精明星星,这篇文章主要介绍java month_Java MonthDay getMonth()用法及代码示例,现在分享给大家,希望可以做个参考。

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(99)

评论列表共有 0 条评论

立即
投稿
返回
顶部