编程语言
首页 > 编程语言> > java8 localDateTime与 Date互相转化

java8 localDateTime与 Date互相转化

作者:互联网

1. 将LocalDateTime传化成 Date

LocalDateTime ldt = LocalDateTime.now();
Date date =Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());

2. 将Date转化成 LocalDateTime

Date date =new Date();
LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(),ZoneId.systemDefault());

标签:toInstant,ldt,ZoneId,date,LocalDateTime,Date,java8,localDateTime
来源: https://blog.csdn.net/xiaojuge/article/details/101272568