Java Data Type How to - Get Europe/Berlin as now in Los Angeles








Question

We would like to know how to get Europe/Berlin as now in Los Angeles.

Answer

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
//from   w  w w.j  av  a 2s.  com
public class Main {
  public static void main(String[] args) {
    ZoneId berlin = ZoneId.of("Europe/Berlin");

    // 2014-02-20 12:00
    LocalDateTime dateTime = LocalDateTime.of(2014, 02, 20, 12, 0);

    // 2014-02-20 12:00, Europe/Berlin (+01:00)
    ZonedDateTime berlinDateTime = ZonedDateTime.of(dateTime, berlin);

    System.out.println(berlinDateTime);
  }
}

The code above generates the following result.