An OffsetDateTime is just a date time with an offset from UTC.
So if you have a fixed offset (e.g. +02 from UTC), you can convert the localDateTime like this :
OffsetDateTime.of(localDateTime, ZoneOffset.of("+2"));
OffsetDateTime.of(localDateTime, ZoneOffset.of("+02"));
OffsetDateTime.of(localDateTime, ZoneOffset.of("+02:00"));
Most of the time you want to have the offset of a specific timezone, in this case it would be preferable to use a ZonedDateTime
because for most timezone the offset is not the same in summer/winter and ZonedDateTime
will automatically handle it for you.
If you absolutely want an OffsetDateTime
with an offset from a specific timezone, you can write :
localDateTime.atZone(ZoneId.of("Europe/Paris")).toOffsetDateTime();
OffsetDataTime::of(LocalDataTime, ZoneOffset)
? – SniperscopeLocalDataTime
is exactly that, a Local... whatever the offset you want to apply is up to you, there are some predefined types, the most commonUTC
I guess – Sniperscope