本文介绍了如何从Instant转换为LocalDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Instant消息,根据规范,该消息应该是LocalDate,但在LocalDate中看不到任何用于转换的方法.最好的方法是什么?

I have an Instant coming from a source that should, according to the spec, be a LocalDate, but don't see any methods in LocalDate for the conversion. What is the best way to do this?

推荐答案

LocalDate.ofInstant(...);我相信是在Java 9中添加的.

LocalDate.ofInstant(...);I believe was added in Java 9.

LocalDateTime在Java 8中具有该方法.

LocalDateTime has that method in Java 8.

yourInstant.atZone(yourZoneId).toLocalDate();将与LocalDate的早期版本一起使用...

yourInstant.atZone(yourZoneId).toLocalDate();Will work with earlier versions for LocalDate...

这篇关于如何从Instant转换为LocalDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:41