/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.time.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { LocalDate localDate = LocalDate.parse( "2016-12-28" ); ZoneId zNewYork = ZoneId.of( "America/New_York" ); ZonedDateTime zdtNewYork = localDate.atStartOfDay( zNewYork ); // First moment of the day in that zone on that date. Instant instant = zdtNewYork.toInstant(); LocalDate originalLocalDate = null; { ZoneId z = ZoneId.of( zoneId ); // Get zone with that name. ZonedDateTime zdt = instant.atZone( z ); LocalDate ld = zdt.toLocalDate(); // Extract the date-only value, dropping the time-of-day and dropping the time zone. ZonedDateTime startOfDay = ld.atStartOfDay( z ); // Determine first moment of the day on that date in that zone. Instant instantOfStartOfDay = startOfDay.toInstant(); // Adjust back to UTC. boolean hit = instant.equals( instantOfStartOfDay ); if ( hit ) { originalLocalDate = ld; hits.add( z ); // Collect this time zone as the zone possibly used originally. } } } }
Standard input is empty
localDate.toString(): 2016-12-28 zdtNewYork.toString(): 2016-12-28T00:00-05:00[America/New_York] instant.toString(): 2016-12-28T05:00:00Z ------------------------------- originalLocalDate.toString(): 2016-12-28 hits.toString(): [America/Panama, America/Indiana/Petersburg, America/Eirunepe, Cuba, Etc/GMT+5, Pacific/Easter, America/Fort_Wayne, America/Havana, America/Porto_Acre, US/Michigan, America/Louisville, America/Guayaquil, America/Indiana/Vevay, America/Indiana/Vincennes, America/Indianapolis, America/Iqaluit, America/Kentucky/Louisville, EST5EDT, America/Nassau, America/Jamaica, America/Atikokan, America/Kentucky/Monticello, America/Coral_Harbour, America/Cayman, Chile/EasterIsland, America/Indiana/Indianapolis, America/Thunder_Bay, America/Indiana/Marengo, America/Bogota, SystemV/EST5, US/Eastern, Canada/Eastern, America/Port-au-Prince, America/Nipigon, Brazil/Acre, US/East-Indiana, America/Cancun, America/Lima, America/Rio_Branco, America/Detroit, Jamaica, America/Pangnirtung, America/Montreal, America/Indiana/Winamac, America/New_York, America/Toronto, SystemV/EST5EDT]