gpt4 book ai didi

android - 使用 getBestDateTimePattern()

转载 作者:太空狗 更新时间:2023-10-29 15:28:23 27 4
gpt4 key购买 nike

根据新闻约Android 4.3

To assist you with managing date formatting across locales, Android 4.3 includes a new getBestDateTimePattern() method that automatically generates the best possible localized form of a Unicode UTS date for a locale that you specify. It’s a convenient way to provide a more localized experience for your users.

如何使用此方法?我找不到它。

最佳答案

7.5 年后,这里有一个带有实际示例的答案! ;-)

Locale locale = Locale.getDefault();
String skeleton = DateFormat.getBestDateTimePattern(locale, "MMMM d, YYYY");

然后,使用 java.time:

Instant.now().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(skeleton));

或者使用遗留类:

Date now = Calendar.getInstance().getTime();
SimpleDateFormat dateTimeFormatter = new SimpleDateFormat(skeleton, locale);
dateTimeFormatter.setTimeZone(TimeZone.getDefault());
dateTimeFormatter.applyLocalizedPattern(skeleton);
dateTimeFormatter.format(now);

关于android - 使用 getBestDateTimePattern(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17869753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com