如何根据地区显示日期格式? [英] How to display date format according to locale?

查看:102
本文介绍了如何根据地区显示日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个提示,提示如何输入日期. 对于德国,它可能看起来像

I want to display a hint how a date should be entered. For Germany it might look like

以这种格式输入日期:dd.mm.yyy"

"Enter date in this format: dd.mm.yyy"

对于美国

以这种格式输入日期:mm/dd/yyyy"

"Enter date in this format: mm/dd/yyyy"

我了解

DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);

我可以将日期转换为与用户的语言环境匹配的格式. 但是,如何获取提示的日/月/年字符串?

I can convert a date into a format matching the user's locale. But how would I get the day/month/year string for the hint?

当然,我也希望类似的东西带有时间提示.

And of course I would want the similar thing with a hint for time, too.

谢谢您的建议.

推荐答案

String hintText = new SimpleDateFormat().toPattern(); // dd/MM/y HH:mm

我知道您只是在询问日期,但这已尽我所能. 内部规则是localeData.getDateFormat(SHORT) + " " + localeData.getTimeFormat(SHORT),所以我猜只要没有一个日期格式带有空格的区域设置,您就可以将字符串拆分为一个空格

I know you were asking for just the date, but this was as close as I can get. The internal rule is localeData.getDateFormat(SHORT) + " " + localeData.getTimeFormat(SHORT) so I guess as long as there is not a locale that has a date format with spaces on it, you can just split the string on a space

这篇关于如何根据地区显示日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆