Handling Time Zones with ZonedDateTime in Java


Use ZonedDateTime to handle date and time with timezone information, useful for international applications.

Source Code

ZonedDateTime zonedDateTime = ZonedDateTime.now(); // Default time zone
ZonedDateTime nyTime = zonedDateTime.withZoneSameInstant(ZoneId.of("America/New_York"));
System.out.println("Current Time: " + zonedDateTime);
System.out.println("New York Time: " + nyTime);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments