Java 8 – Create Instant from LocalDateTime with TimeZone [duplicate]

You can first create a ZonedDateTime with that time zone, and then call toInstant:

LocalDateTime dateTime = LocalDateTime.of(2017, Month.JUNE, 15, 13, 39);
Instant instant = dateTime.atZone(ZoneId.of("Europe/Paris")).toInstant();
System.out.println(instant); // 2017-06-15T11:39:00Z

I also switched to using the full time zone name (per Basil’s advice), since it is less ambiguous.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)