Here you can find the source of toCalendar(OffsetDateTime offsetDateTime)
Parameter | Description |
---|---|
offsetDateTime | the date time to convert |
public static Calendar toCalendar(OffsetDateTime offsetDateTime)
//package com.java2s; //License from project: LGPL import java.time.OffsetDateTime; import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Objects; import java.util.TimeZone; public class Main { /**// w ww.j a va 2s.c om * Convert the given {@link OffsetDateTime} instance to {@link Calendar} instance with the same time and time zone * * @param offsetDateTime * the date time to convert * @return the converted calendar instance */ public static Calendar toCalendar(OffsetDateTime offsetDateTime) { Objects.requireNonNull(offsetDateTime, "Offset date time is required"); TimeZone timeZone = TimeZone.getTimeZone(offsetDateTime.toZonedDateTime().getZone()); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(offsetDateTime.toInstant().toEpochMilli()); calendar.setTimeZone(timeZone); return calendar; } /** * Convert the given {@link ZonedDateTime} instance to {@link Calendar} instance with the same time and time zone * * @param zonedDateTime * the date time to convert * @return the converted calendar instance */ public static Calendar toCalendar(ZonedDateTime zonedDateTime) { Objects.requireNonNull(zonedDateTime, "Zoned date time is required"); TimeZone timeZone = TimeZone.getTimeZone(zonedDateTime.getZone()); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(zonedDateTime.toInstant().toEpochMilli()); calendar.setTimeZone(timeZone); return calendar; } }