Is there an easy way to achieve System.currentTimeMillis()
to 2017-04-13T19:00:00+08:00
using java.time
?
I have tried tremendous amount of methods so far, but it either gives the correct zone but in a wrong language, or does not give any zone at all.
Instant shanghai= Instant.ofEpochMilli(System.currentTimeMillis());
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL)
.withZone(ZoneId.of("Asia/Shanghai"));
System.out.println(formatter.format(shanghai));
BTW, maybe it's because I haven't used Java 8 time API enough times to see its beauty, but I do feel it as "drawing snake with feet".
For example, withZone
sounds like it shifts time result to accommodate zone. But it actually change the language too, which I think should only be related to Locale
.