List of usage examples for java.time ZonedDateTime withZoneSameInstant
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime l = dateTime.withZoneSameInstant(ZoneId.systemDefault()); System.out.println(l);//from w w w .j a va2 s . co m }
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) { 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) { 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[] 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 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) { 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); }
From source file:org.openhab.binding.gardena.internal.util.DateUtils.java
/** * Converts a string to a Date, trying different date formats used by Gardena. *//*from ww w. j a v a2s .co m*/ public static Date parseToDate(String text) { if (StringUtils.isNotBlank(text)) { Date parsedDate = null; for (String dateFormat : dateFormats) { try { parsedDate = new SimpleDateFormat(dateFormat).parse(text); ZonedDateTime gmt = ZonedDateTime.ofInstant(parsedDate.toInstant(), ZoneOffset.UTC); LocalDateTime here = gmt.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); parsedDate = Date.from(here.toInstant(ZoneOffset.UTC)); break; } catch (ParseException ex) { } } if (parsedDate == null) { LOGGER.error("Can't parse date {}", text); } return parsedDate; } else { return null; } }