List of usage examples for java.time ZoneId of
public static ZoneId of(String zoneId)
From source file:Main.java
public static void main(String[] args) { LocalTime now = LocalTime.now(); LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles")); System.out.println(String.format("now is %s and in LA is %s", now, currentTimeInLosAngeles)); ZoneId leavingZone = ZoneId.of("Asia/Tel_Aviv"); ZoneId arrivingZone = ZoneId.of("America/New_York"); LocalDateTime leaving = LocalDateTime.of(2014, Month.JULY, 16, 23, 00); ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone); ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusHours(11).plusMinutes(51); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d HH:mm"); System.out.println(String.format("Departure: %s", departure.format(format))); System.out.println(String.format("Arrival: %s", arrival.format(format))); }
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[] argv) { Date dateFromInstant = Date.from(Instant.now()); System.out.println(dateFromInstant); java.util.TimeZone timeZone = java.util.TimeZone.getTimeZone(ZoneId.of("America/Los_Angeles")); System.out.println(timeZone); GregorianCalendar gregorianCalendar = GregorianCalendar.from(ZonedDateTime.now()); }
From source file:Main.java
public static void main(String[] args) { // Date to Instant Instant timestamp = new Date().toInstant(); // convert Instant to LocalDateTime or other similar classes LocalDateTime date = LocalDateTime.ofInstant(timestamp, ZoneId.of(ZoneId.SHORT_IDS.get("PST"))); System.out.println("Date = " + date); }
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[] args) { ZonedDateTime zdt1 = ZonedDateTime.now(); System.out.println("Current zoned datetime:" + zdt1); LocalDateTime ldt = LocalDateTime.of(2012, Month.MARCH, 11, 7, 30); ZoneId usCentralZone = ZoneId.of("America/Chicago"); ZonedDateTime zdt2 = ZonedDateTime.of(ldt, usCentralZone); System.out.println(zdt2);/*from w w w . j a v a2s . com*/ }
From source file:Main.java
public static void main(String[] args) { Clock utcClock = Clock.systemUTC(); Clock defaultClock = Clock.systemDefaultZone(); Clock offsetClock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-5)); ZoneId denverTimeZone = ZoneId.of("America/Denver"); ZoneId newYorkTimeZone = ZoneId.of("America/New_York"); ZoneId chicagoTimeZone = ZoneId.of("America/Chicago"); ZoneId losAngelesTimeZone = ZoneId.of("America/Los_Angeles"); Instant instant = Instant.now(defaultClock); Instant instant2 = Instant.now(utcClock); Instant instant3 = Instant.now(offsetClock); System.out.println(instant);// ww w .j av a 2 s .c o m System.out.println(instant2); System.out.println(instant3.plus(Duration.ofSeconds(90))); System.out.println(instant3.atZone(newYorkTimeZone)); System.out.println(instant3.atZone(chicagoTimeZone)); System.out.println(instant3.atZone(denverTimeZone)); System.out.println(instant3.atZone(losAngelesTimeZone)); }
From source file:Main.java
public static void main(String[] args) { String strDate = "2015-09-12 23:59:59"; String pattern = "yyyy-MM-dd HH:mm:ss"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); ZoneId zone = ZoneId.of("America/Los_Angeles"); long milli = getMillis(strDate, formatter, zone); System.out.println(milli);/*from w w w . jav a 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) { LocalTime lt = LocalTime.of(16, 30, 5, 78899); format(lt, "HH:mm:ss"); format(lt, "KK:mm:ss a"); format(lt, "[MM-dd-yyyy][' at' HH:mm:ss]"); ZoneId usCentral = ZoneId.of("America/Chicago"); ZonedDateTime zdt = ZonedDateTime.of(LocalDate.now(), lt, usCentral); format(zdt, "MM/dd/yyyy HH:mm:ssXXX"); format(zdt, "MM/dd/yyyy VV"); format(zdt, "[MM-dd-yyyy][' at' HH:mm:ss]"); }
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"); LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30); // Leaving from San Francisco on July 20, 2013, at 7:30 p.m. ZoneId leavingZone = ZoneId.of("America/Los_Angeles"); ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone); String out1 = departure.format(format); System.out.printf("LEAVING: %s (%s)%n", out1, leavingZone); // Flight is 10 hours and 50 minutes, or 650 minutes ZoneId arrivingZone = ZoneId.of("Asia/Tokyo"); ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusMinutes(650); String out2 = arrival.format(format); System.out.printf("ARRIVING: %s (%s)%n", out2, arrivingZone); }