Это полный код, который я сделал, чтобы получить ответ:
TimeZone.setDefault(null);
System.setProperty("user.timezone", "");
//(above) force fetches and sets the JVM to the timezone the system is set to
LocalDateTime currentDateTime = LocalDateTime.of(date.getYear(), date.getMonth(), date.getDay(), hour, minute, 0);
ZonedDateTime zonedDateTime = currentDateTime.atZone(ZoneId.systemDefault());
date = Date.from(zonedDateTime.toInstant());
Проблема заключалась в том, что я мог изменить системный часовой пояс, как упомянуто @Matt.Однако я обнаружил, что время JVM не изменилось, несмотря на ручное изменение часового пояса.
TimeZone.setDefault(null);
System.setProperty("user.timezone", "");
(выше) Позволил мне очистить ранее установленный часовой пояс JVM.
РЕДАКТИРОВАТЬ 04/26/2019
Я обновил свою логикудля поддержки перехода на летнее время по тихоокеанскому времени.Я столкнулся с проблемой, когда мое время устанавливало PST вместо PDT, поэтому вместо вышеуказанной логики я изменил ее, чтобы получить идентификатор зоны и использовать его с классом Calendar.Ниже приведена законченная логика:
TimeZone.setDefault(null);
System.clearProperty("user.timezone"); //04/26/2019 EDIT This was suggested as a cleaner way of clearing the user timezone in the system.
//(above) force fetches and sets the JVM to the timezone the system is set to
System.out.println("Zone: "+ZoneId.systemDefault()+" isDaylightsavings? "+ZoneId.systemDefault().getRules().isDaylightSavings(Instant.now())+" currentDateTime: "+currentDateTime);
String timeZone = ""+ZoneId.systemDefault();
Calendar selectedDate = Calendar.getInstance(TimeZone.getTimeZone(timeZone)); // important when it comes to determining PDT or PST
date = selectedDate.getTime();