Converting java.time to Calendar

后端 未结 3 627
一个人的身影
一个人的身影 2021-02-18 16:18

What is the simplest way of getting a Calendar object from a java.time.Instant or java.time.ZonedDateTime?

3条回答
  •  失恋的感觉
    2021-02-18 16:42

    You need to get the TimeZone using the instant and then you can get a calendar.

    Calendar myCalendar = GregorianCalendar.from(ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
    

提交回复
热议问题