Answers for "java zoneddatetime"

1

java zoneddatetime

LocalDateTime now = LocalDateTime.now();
System.out.println(now);
System.out.println("ZoneId.systemDefault(): " + ZoneId.systemDefault());

// convert LocalDateTime to ZonedDateTime, with default system zone id
ZonedDateTime zonedDateTime = now.atZone(ZoneId.systemDefault());

// convert LocalDateTime to ZonedDateTime, with specified zoneId
ZonedDateTime europeDateTime = zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Kaliningrad"));
System.out.println(europeDateTime);

// convert LocalDateTime to ZonedDateTime, with specified off set
ZonedDateTime offSetNegative5 = now.atOffset(ZoneOffset.of("-05:00")).toZonedDateTime();
System.out.println(offSetNegative5);

// display all zone ids
//ZoneId.getAvailableZoneIds().forEach(System.out::println);

// output
/*
2021-03-23T16:43:32.010069453
ZoneId.systemDefault(): Asia/Kuala_Lumpur
2021-03-23T10:43:32.010069453+02:00[Europe/Kaliningrad]
2021-03-23T16:43:32.010069453-05:00
*/
Posted by: Guest on July-05-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language