Java 8 – Converting dates between different time zones

The simplest way that I found to convert between different time zones using only Java 8 APIs.

ZonedDateTime targetDate = ZonedDateTime
    .parse("2016-11-20T11:00:00-05:00")
    .withZoneSameInstant(ZoneId.of("America/Argentina/Buenos_Aires"));
Original date 2016-11-20T11:00:00-05:00
America/Argentina/Buenos_Aires 2016-11-20T13:00:00-03:00
America/Sao_Paulo 2016-11-20T14:00:00-02:00

Do you have a simpler way? Please comment here. 🙂

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>