I am trying to get the current UTC time and convert it into a Date object:
OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
Date date = Date.from(now.toInstant());
The problem I face is that OffsetDateTime
returns the correct time, for example 2023-03-22T08:46:38.562331200Z
, which is correct in the time of writing, but when converting it to Date
object the date
becomes Wed Mar 22 10:46:38 EET 2023
with my timezone EET, how can I create a Date object with the UTC time 2023-03-22T08:46:38.562331200Z retrieved?