How to covert Joda-Time's DateTimeFormat.forStyle() to JSR 310 JavaTime?

人走茶凉 提交于 2019-12-01 13:18:48

The methods ofLocalizedDate(), ofLocalizedTime() and ofLocalizedDateTime() provide the localized formats.

To format an Instant a time-zone is required. This can be added to the formatter using withZone():

DateTimeFormatter formatter =
    DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
                     .withLocale(UK)
                     .withZone(ZoneId.systemDefault());

Without the zone, JSR-310 formatter has no knowledge of how to convert the instant to human date-time fields.

stokito

JSR 310 has other ways to replace style: DateTimeFormatter.ofLocalizedTime(), DateTimeFormatter.ofLocalizedDate() and DateTimeFormatter.ofLocalizedDateTime()

Other problem is that Instant type can't be formatted Format Instant to String

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!