I want to create an instance of ZonedDateTime from String. I want to make "2021-03-18 8:00:00" turn into "2021-03-18 8:00:00 EST". I don't want an unexpected variable to interfere by converting 8:00:00 to a different time from what is shown. i.e from 8:00:00 to 17:00:00.
The code that I used to try to convert it was:
SimpleDateFormat estForm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
estForm.setTimeZone(TimeZone.getTimeZone("EST"));
String start = "2021-03-18 08:00:00";
Date estDT = estForm.parse(start);
final ZoneId zoneEST = ZoneId.of("US/Eastern");
ZonedDateTime zoneEst = ZonedDateTime.ofInstant(estDT.toInstant(), zoneEST);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(zoneEST);
System.out.println(zoneEst);
Here is the last output I got from this:
US/Eastern
2021-03-18T09:00-04:00[US/Eastern]