LocalDateTime toLocalDate() 方法在 Java 中
可以使用 LocalDateTime 类的 toLocalDate() 方法获取 LocalDate 的表示形式。此方法不需要参数,并且它返回 LocalDateTime 对象的 LocalDate 值。
以下是演示此方法的一个程序 −
示例
import java.time.*;
import java.util.*;
public class Demo {
public static void main(String[] args) {
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("The LocalDateTime is: " + ldt);
System.out.println("The LocalDate representation is: " + ldt.toLocalDate());
}
}输出
The LocalDateTime is: 2019-02-18T23:15:30 The LocalDate representation is: 2019-02-18
现在让我们了解一下上面的程序。
首先显示 LocalDateTime。然后使用 toLocalDate() 方法获取 LocalDate 的表示形式并显示它。演示此方法的代码片段如下 −
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("The LocalDateTime is: " + ldt);
System.out.println("The LocalDate representation is: " + ldt.toLocalDate());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP