Java程序将java.util.Date转换为java.time.LocalDateTime
首先,设置日期-
java.util.Date date = new Date();
现在,将上述日期转换为java.time.LocalDateTime-
java.time.LocalDateTime dateTime =java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
示例
import java.time.ZoneId;import java.util.Date;
public class Demo {
public static void main(String[] args) {
java.util.Date date = new Date();
System.out.println("Date = "+date);
java.time.LocalDateTime dateTime =
java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
System.out.println("LocalDateTime = "+dateTime);
}
}
输出结果
Date = Thu Apr 18 23:39:34 IST 2019LocalDateTime = 2019-04-18T23:39:34.400
以上是 Java程序将java.util.Date转换为java.time.LocalDateTime 的全部内容, 来源链接: utcz.com/z/331396.html