Java Data Type How to - Convert local date time to date time another timezone








Question

We would like to know how to convert local date time to date time another timezone.

Answer

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/*w w  w. j ava  2s  .  co  m*/
public class Main {

  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2013, 11, 12);
    LocalTime localTime = LocalTime.of(23, 10, 44, 12882);
    ZoneId chicago = ZoneId.of("America/Chicago");
    ZonedDateTime chicagoTime = ZonedDateTime.of(localDate, localTime, chicago);
    System.out.println(chicagoTime);
  }
}

The code above generates the following result.