gpt4 book ai didi

android - 乔达和安卓 : How to format a date for display in the user's locale?

转载 作者:行者123 更新时间:2023-11-29 20:51:54 25 4
gpt4 key购买 nike

我正在使用 Joda 库。我的要求是显示的日期字符串适合用户的区域设置,即在德国设备 12.12.2014 和美国设备 2014/12/12 上。我发现我可以使用 LocalDate 的 toString() 方法。

LocalDate localDate = LocalDate.now();
localDate.toString("yyyy/MM/dd", Locale.getDefault());

如果我理解正确,我需要提供一个模式,但恕我直言,这违背了指定语言环境的目的。

谁能教教我?

最佳答案

我的解决方案,将格式化适合设备区域设置的显示日期:

        DateTimeFormatter fmt = DateTimeFormat.mediumDate();
String str = fmt.print(localDate);
getGeburtsdatumEditText().setText(str);

关于android - 乔达和安卓 : How to format a date for display in the user's locale?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28918669/

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