DESKTOP-7803S27_20200902-吴远亮
问题
练习 LocalDateTime 和Date之间的互相转换。
代码如下
LocalDateTime 转换为Date
LocalDateTime ldt = LocalDateTime.of(2020, 9, 2, 19, 30, 36);
System.out.println( ldt );
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime zdt = ldt.atZone( zone );
Instant ins = zdt.toInstant() ;
Date date = Date.from( ins) ;
System.out.println(date);
Date 转换为 LocalDateTime
Date date=new Date();
System.out.println(date);
Instant ist=date.toInstant();
ZoneId zone=ZoneId.systemDefault();
ZonedDateTime zdt=ist.atZone(zone);
LocalDateTime ldt =zdt.toLocalDateTime();
System.out.println(ldt);
吐槽
今天学习的内容基本上都能够理解,但是对于方法的还不够熟练,还需要多加练习。
点赞

