Trying to convert a various of time formats to a unified format.
One format is
"uuuu-MM-dd'T'HH:mm:ss-5000"
need to convert to the timezone format:
"uuuu-MM-dd'T'HH:mm:ss EST"
Using the following code, but it only gives the timezone as "-05:00", but not the expected "EST".
String targetFormat = "uuuu-MM-dd'T'HH:mm:ss z";
String origFormat = "uuuu-MM-dd'T'HH:mm:ss.SSSZ";
String origStr = "2018-02-05T17:25:18.156-0500";
ZonedDateTime time = ZonedDateTime.parse(origStr, DateTimeFormatter.ofPattern(origFormat));
String targetStr = time.format(DateTimeFormatter.ofPattern(targetFormat));
Output from the above is:
2018-02-05T17:25:18 -05:00
How to get the expected:
2018-02-05T17:25:18 EST