MonthDay get() 方法在 Java 中
可以通过 Java 中 MonthDay 类中的 get() 方法获取 MonthDay 指定字段的值。此方法需要一个参数,即必需的 ChronoField,然后它将返回 MonthDay 中指定字段的值。
如下所示,这是展示的程序。
示例
import java.time.*;
import java.time.temporal.*;
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_OF_YEAR is: " + md.get(ChronoField.MONTH_OF_YEAR));
}
}输出
The MonthDay is: --02-22 The MONTH_OF_YEAR is: 2
现在让我们理解上述程序。
首先,MonthDay 对象显示。然后,使用 get() 方法从 MonthDay 对象获取 ChronoField MONTH_OF_YEAR 的值并打印。用于演示的代码片段如下所示:
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
System.out.println("The MONTH_OF_YEAR is: " + md.get(ChronoField.MONTH_OF_YEAR));
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP