Specify timezone of ZonedDateTime without changing the actual date

2381 views java
-1

I have a Date object which holds a date (not current date) and I need to somehow specify that this date is UTC and then convert it to "Europe/Paris" which is +1 hours.

public static LocalDateTime toLocalDateTime(Date date){
    return ZonedDateTime.of(LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC), ZoneId.of("Europe/Paris")).toLocalDateTime();
}

Given a date of "2018-11-08 15:00:00" this converts the date into "2018-11-08 14:00:00". I need it to convert from UTC to Europe/Paris - not the other way around.

answered question

1 Answer

8

 ZonedId zoneId = ZoneId.of("Europe/Paris");
 return ZonedDateTime.of(LocalDateTime.ofInstant(date.toInstant(),zonedId);

Try to define ZoneId that is Europe/Paris

posted this

Have an answer?

JD

Please login first before posting an answer.