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) {
    // Current time in "Asia/Kolkata"
    LocalTime timeKolkata = LocalTime.now(ZoneId.of("Asia/Kolkata"));
    System.out.println("Current Time in IST=" + timeKolkata);
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime nowInAthens = ZonedDateTime.now(ZoneId.of("Europe/Athens"));

    System.out.println(nowInAthens.withZoneSameInstant(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(3))));
}

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) {
    Instant i1 = Instant.now();

    ZoneId usChicago = ZoneId.of("America/Chicago");
    OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(i1, usChicago);
    System.out.println(offsetDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    //Current date in "Asia/Kolkata"
    LocalDateTime todayKolkata = LocalDateTime.now(ZoneId.of("Asia/Kolkata"));
    System.out.println("Current Date in IST=" + todayKolkata);
}

From source file:Main.java

public static void main(String[] argv) {
    ZoneId INDIA = ZoneId.of("Asia/Kolkata");

    LocalDateTime utah = LocalDateTime.now();
    LocalDateTime india = LocalDateTime.now(INDIA);
    long betweenHours = ChronoUnit.HOURS.between(utah, india);
    long betweenMins = ChronoUnit.MINUTES.between(utah, india);
    System.out.println("betweenHours = " + betweenHours);
    System.out.println("betweenMins = " + (betweenMins / 60.0));
}

From source file:Main.java

public static void main(String[] argv) {
    ZoneId INDIA = ZoneId.of("Asia/Kolkata");

    LocalDateTime datetime = LocalDateTime.now();
    ZoneOffset offset = ZoneOffset.of("+05:30");
    OffsetDateTime date = OffsetDateTime.of(datetime, offset);

    System.out.println("OffsetDateTime.now() = " + OffsetDateTime.now());
    System.out.println("OffsetDateTime.now(TimeZone.INDIA) = " + OffsetDateTime.now(INDIA));
    System.out.println("Date and Time: " + datetime);
    System.out.println("Date and Time with timezone offset: " + date);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usChicago = ZoneId.of("America/Chicago");

    // 2014-03-09T02:30 did not exist in America/Chicago time zone
    LocalDateTime ldt = LocalDateTime.of(2014, Month.MARCH, 9, 2, 30);
    ZonedDateTime zdt = ZonedDateTime.of(ldt, usChicago);
    System.out.println(zdt);/*from   w  ww  .  ja  v  a2  s  . com*/

    // 2013-10-03T01:30 existed twice in America/Chicago time zone
    LocalDateTime ldt2 = LocalDateTime.of(2013, Month.NOVEMBER, 3, 1, 30);
    ZonedDateTime zdt2 = ZonedDateTime.of(ldt2, usChicago);

    System.out.println(zdt2.withEarlierOffsetAtOverlap());
    System.out.println(zdt2.withLaterOffsetAtOverlap());

}

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  w  w  .j a  va2s.  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    // Current date in "Asia/Kolkata", you can get it from ZoneId javadoc
    LocalDate todayKolkata = LocalDate.now(ZoneId.of("Asia/Kolkata"));
    System.out.println("Current Date in IST=" + todayKolkata);
}