How do I format a javax.time.Instant as a string in the local time zone? The following translates a local Instant
to UTC, not to the local time zone as I was expec
Try this:
String dateTime = DateTimeFormatter.ISO_ZONED_DATE_TIME.format(
ZonedDateTime.ofInstant(instant, ZoneId.systemDefault())
);
This gives:
2014-08-25T21:52:07-07:00[America/Los_Angeles]
You can change the format by using something other than DateTimeFormatter.ISO_ZONED_DATE_TIME
as the formatter. DateTimeFormatter has a bunch of predefined formatters, or you can define your own.