Example usage for java.time ZonedDateTime of

List of usage examples for java.time ZonedDateTime of

Introduction

In this page you can find the example usage for java.time ZonedDateTime of.

Prototype

public static ZonedDateTime of(LocalDateTime localDateTime, ZoneId zone) 

Source Link

Document

Obtains an instance of ZonedDateTime from a local date-time.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());

    System.out.println(z);/*from  ww  w  . j  av  a2 s .  c o m*/

    LocalDateTime timePoint = LocalDateTime.now();
    ZoneId id = ZoneId.of("Europe/Paris");
    ZonedDateTime zoned = ZonedDateTime.of(timePoint, id);

    System.out.println(zoned);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime dtPrevistaBR = LocalDateTime.of(2014, 3, 26, 10, 35);

    ZonedDateTime localOrigemZone = ZonedDateTime.of(dtPrevistaBR, ZoneId.systemDefault());

    ZoneId localEntregaZoneId = ZoneId.of("America/Bogota");
    ZonedDateTime dtPrevista = localOrigemZone.withZoneSameInstant(localEntregaZoneId);

    System.out.println("Data Prevista (Brasileira): " + dtPrevistaBR);
    System.out.println("Data Prevista (Bogota): " + dtPrevista.toLocalDateTime());
}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime localDateTime = LocalDateTime.of(1982, Month.APRIL, 17, 14, 11);
    ZonedDateTime jakartaTime = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Jakarta"));
    System.out.println(jakartaTime); //1982-04-17T14:11+07:00[Asia/Jakarta]

    System.out.println(jakartaTime.withZoneSameInstant(ZoneId.of("America/Los_Angeles"))); //1982-04-16T23:11-08:00[America/Los_Angeles]
    System.out.println(jakartaTime.withZoneSameLocal(ZoneId.of("America/New_York"))); //1982-04-17T14:11-05:00[America/New_York]

}

From source file:Main.java

public static void main(String[] args) {

    LocalDateTime l = LocalDateTime.of(2012, Month.AUGUST, 13, 0, 0, 0);
    ZonedDateTime z = ZonedDateTime.of(LocalDateTime.of(2014, Month.AUGUST, 13, 0, 0, 0),
            ZoneId.of("America/Los_Angeles"));

    Duration duration = Duration.between(l, z);

    System.out.println(duration);
}

From source file:Main.java

public static void main(String[] argv) {

    LocalDateTime now = LocalDateTime.now();
    ZonedDateTime zonedDateTime = ZonedDateTime.of(now, TimeZone.NEW_YORK);
    System.out.println("now = " + now);
    System.out.println("Current date and time in a particular timezone : " + zonedDateTime);

    now = LocalDateTime.now(TimeZone.INDIA);
    System.out.println("now in India = " + now);

    zonedDateTime = ZonedDateTime.now();
    System.out.println("zonedDateTime with default(system) timezone = " + zonedDateTime);
    System.out.println("zonedDateTime with India timezone = " + ZonedDateTime.now(TimeZone.INDIA));

    String isoFormatted = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(TimeZone.INDIA));
    System.out.println("ISO Formatted = " + isoFormatted);

    ZonedDateTime utahMarch8thAt2AM = ZonedDateTime.of(LocalDateTime.of(2015, 3, 8, 1, 0), TimeZone.UTAH);
    System.out.println("utahMarch8thAt2AM = " + utahMarch8thAt2AM);
    System.out.println("utahMarch8thAt2AM.plusHours(1) = " + utahMarch8thAt2AM.plusHours(1));
    System.out.println("utahMarch8thAt2AM.plusHours(2) = " + utahMarch8thAt2AM.plusHours(2));
}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime ldt = LocalDateTime.of(2014, Month.JUNE, 21, 16, 30);

    ZoneId usCentral = ZoneId.of("America/Chicago");
    ZonedDateTime zdt = ZonedDateTime.of(ldt, usCentral);
    System.out.println("In US  Central Time Zone:" + zdt);

    ZoneId losAngeles = ZoneId.of("America/Los_Angeles");
    ZonedDateTime zdt2 = zdt.withZoneSameInstant(losAngeles);
    System.out.println("In  America/Los_Angeles Time Zone:" + zdt2);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30);

    ZoneId leavingZone = ZoneId.of("America/Los_Angeles");
    ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

    System.out.println(departure);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usCentral = ZoneId.of("America/Chicago");
    LocalDateTime ldt = LocalDateTime.of(2012, Month.MARCH, 10, 7, 30);
    ZonedDateTime zdt1 = ZonedDateTime.of(ldt, usCentral);
    Period p1 = Period.ofDays(1);

    ZonedDateTime zdt2 = zdt1.plus(p1);
    System.out.println(zdt2);//from w  ww .j  ava 2  s .  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usCentral = ZoneId.of("America/Chicago");
    LocalDateTime localDateTime = LocalDateTime.of(2014, Month.MAY, 21, 9, 30);
    System.out.println(localDateTime);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, usCentral);
    System.out.println(zonedDateTime);
}

From source file:Main.java

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);
}