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
*/

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source