I have to display local date time for different countries in java.Currently I am setting zoneId for "America/New_York" and so only getting EST time for all the places on the server.How to achieve local date/time dynamically.
DateTimeFormatter globalFormat = DateTimeFormatter.ofPattern("dd-MMM-yyyy hh:mm a z");
DateTimeFormatter estFormat = DateTimeFormatter.ofPattern("dd-MMM-yyyy hh:mm a 'EST'");
ZoneId istZoneId = ZoneId.of("Asia/Calcutta");
ZoneId estZoneId = ZoneId.of("America/New_York");
Instant instant = Instant.now() ;
ZonedDateTime zdt = ZonedDateTime.now( estZoneId) ;
ZonedDateTime currentISTime = instant.atZone(istZoneId); //India time
ZonedDateTime currentESTime = zdt.withZoneSameInstant(estZoneId); //EST Time
System.out.println("est time.............."+estFormat.format(currentESTime));