To convert GregorianCalendar
to OffsetDateTime
, convert ZonedDateTime
and then call toOffsetDateTime()
method.
import java.time.OffsetDateTime; import java.util.GregorianCalendar; public class Main { public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(2020, 2, 21, 15, 23, 39); //w ww .j a v a 2 s. c om OffsetDateTime od = gc.toZonedDateTime().toOffsetDateTime(); System.out.println("Offset Date: " + od); } }