I have the following DateTimeFormatter .
DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a zzzz");
I use it to format ZonedDateTime as follows:
ZonedDateTime disableTime = Instant.now() .plus(Duration.ofDays(21)) .atZone(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(-5))); System.out.println(DATE_TIME_FORMATTER.format(disableTime));
I would like this to create a formatted date string, for example the following:
09/16/2015 at 01:15:45 PM EDT
But what happens:
09/16/2015 at 01:15:45 PM UTC-05: 00
Regardless of whether I use z , zz , zzz or zzzz in the template, it is always displayed in the above format.
Is there any other way to create a ZonedDateTime that will give me the desired result, or am I doing something wrong in the template?
According to the documentation, DateTimeFormatter O should be used to display a localized zone offset, such as UTC-05:00 , and z should be used to display a time zone name, such as Eastern Daylight Time or EDT .
java java-8 java-time
Andrew Mairose
source share