Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Main {
    public static void main(String[] args) {
        ZoneId berlin = ZoneId.of("Europe/Berlin");
        ZoneId losAngeles = ZoneId.of("America/Los_Angeles");
        // 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);

        // 2014-02-20 03:00, America/Los_Angeles (-08:00)
        ZonedDateTime losAngelesDateTime = berlinDateTime.withZoneSameInstant(losAngeles);

        System.out.println(losAngelesDateTime);
    }
}