Java中的MonthDay getMonthValue()方法
使用Java中MonthDay类中的getMonthValue()方法获得一年中的月份。此方法不需要任何参数,它返回一年中的月份,范围在1到12之间。
演示此程序如下
示例
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 month is: " + md.getMonthValue());
}
}输出结果
The MonthDay is: --02-22 The month is: 2
现在让我们了解上面的程序。
首先显示MonthDay。然后使用getMonthValue()方法获取一年中的月份并显示出来。演示此代码段如下所示:
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The month is: " + md.getMonthValue());热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短