我需要ZonedDateTime
根据稍后获得的语言环境进行输出。有什么方法可以将ZonedDateTime
值转换为所需的格式?
ZonedDateTime creationDate=ZonedDateTime.now();
//convert creationDate depending on the existing locale
ZonedDateTime不具备的格式。ZonedDateTime的概念是无格式的。
格式化程序是他们自己的对象(的实例DateTimeFormatter
)。它们是可配置的(例如,您可以更改其区域设置,然后它们所做的所有特定于区域设置的呈现方式(例如长格式月份名称)都将更改),并且您可以要求他们格式化提供的zoneddatetime。
因此,可以随时创建zoneddatetime对象,并将其存储在任何位置。如果3天后,您需要根据您刚刚获得的某种语言环境对其进行格式化,那就太好了。然后执行以下操作:
ZonedDateTime zdt = ZonedDateTime.now();
// days pass
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).localizedBy(Locale.FRENCH);
System.out.println(dtf.format(zdt));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句