LocalDate getMonth() 方法在 Java 中
局部日期的月份名称可以使用 Java 中 LocalDate 类的 getMonth() 方法获得。此方法不需要参数,它返回在年中的月份名称。
一个演示此方法的程序如下所示
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
LocalDate ld = LocalDate.parse("2019-02-14");
System.out.println("The LocalDate is: " + ld);
System.out.println("The month is: " + ld.getMonth());
}
}输出
The LocalDate is: 2019-02-14 The month is: FEBRUARY
现在让我们理解上述程序。
首先显示 LocalDate。然后使用 getMonth() 方法显示 LocalDate 的月份名称。一个演示此方法的代码片段如下所示
LocalDate ld = LocalDate.parse("2019-02-14");
System.out.println("The LocalDate is: " + ld);
System.out.println("The month is: " + ld.getMonth());
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP