Example usage for java.time ZoneId of

List of usage examples for java.time ZoneId of

Introduction

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

Prototype

public static ZoneId of(String zoneId) 

Source Link

Document

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZoneId z = ZoneId.of("UTC");

    System.out.println(z);
}

From source file:Main.java

public static void main(String... args) {
    ZoneId zone1 = ZoneId.of("Europe/Berlin");
    ZoneId zone2 = ZoneId.of("Brazil/East");

    LocalTime now1 = LocalTime.now(zone1);
    LocalTime now2 = LocalTime.now(zone2);

    System.out.println(now1);//from  www.j a v a2s.  c o m
    System.out.println(now2);

}

From source file:Main.java

public static void main(String... args) {
    ZoneId zone1 = ZoneId.of("Europe/Berlin");
    ZoneId zone2 = ZoneId.of("Brazil/East");

    LocalTime now1 = LocalTime.now(zone1);
    LocalTime now2 = LocalTime.now(zone2);

    System.out.println(now1);/*  ww  w  . j av a2s  . c  o m*/
    System.out.println(now2);

    System.out.println(now1.isBefore(now2)); // false

}

From source file:Main.java

public static void main(String[] argv) {
    ZonedDateTime paris = ZonedDateTime.now(ZoneId.of("Europe/Paris"));
    ZonedDateTime london = ZonedDateTime.now(ZoneId.of("Europe/London"));
    System.out.println(paris.getHour() - london.getHour());
}

From source file:Main.java

public static void main(String[] args) {

    LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles"));
    System.out.println(currentTimeInLosAngeles); // 23:08:18.104
}

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

From source file:Main.java

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

From source file:Main.java

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

    int offsetInSeconds = losAngelesDateTime.getOffset().getTotalSeconds(); // -28800

    System.out.println(offsetInSeconds);
}

From source file:Main.java

public static void main(String[] argv) {
    ZonedDateTime here = ZonedDateTime.now(ZoneId.of("America/Los_Angeles"));
    ZonedDateTime gmtNewYear = ZonedDateTime.of(2014, 12, 31, 23, 59, 59, 0, ZoneId.of("Europe/London"));

    Duration d = Duration.between(here, gmtNewYear);
    System.out.println(d);/*from   w ww .  ja  v  a 2  s . com*/
}

From source file:Main.java

public static void main(String... args) {
    ZoneId zone1 = ZoneId.of("Europe/Berlin");
    ZoneId zone2 = ZoneId.of("Brazil/East");

    LocalTime now1 = LocalTime.now(zone1);
    LocalTime now2 = LocalTime.now(zone2);

    System.out.println(now1);/*from www. j ava2  s  .  c om*/
    System.out.println(now2);

    long hoursBetween = ChronoUnit.HOURS.between(now1, now2);
    long minutesBetween = ChronoUnit.MINUTES.between(now1, now2);
    System.out.println(hoursBetween);
    System.out.println(minutesBetween);

}