How to convert from Instant to LocalDate

前端 未结 5 843
旧巷少年郎
旧巷少年郎 2020-12-14 06:10

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 t

5条回答
  •  佛祖请我去吃肉
    2020-12-14 06:23

    You need to ask yourself at what zone offset you want to transform it to most probably and when you know the answer to that:

    LocalDate.ofInstant(yourInstant, yourZoneOffSet)
    

    EDIT

    just realized that this is only possible since java-9, for a pre-java9 see the other answer

提交回复
热议问题