Java 中的本地化相对日期格式
我想显示这样的日期:
[相对],短月日年小时:分钟 [AM|PM] [时区]
对于 Locale.ENGLISH 例如:
Today, Jan 26, 2012 07:41 PM CET
对于 Locale GERMAN 例如:
Heute, 26. Jan 2012 19:41 MEZ
对于几天前的日期:
Jan 22, 2012 07:41 PM CET
因此,[RELATIVE]-“前缀”应该仅在“可用”时出现(使用 ICU4J),否则我们想查看确切的日期;我们希望根据区域设置自动从 12/24 小时表示法切换 模式
不起作用,因为没有该相关事物的标识符,也没有基于区域设置自动 12/24 小时的 hh:mm 标识符。
有什么想法吗?
I would like to display dates like this:
[RELATIVE], SHORT-MONTH DAY YEAR HOURS:MINS [AM|PM] [TIMEZONE]
For Locale.ENGLISH e.g.:
Today, Jan 26, 2012 07:41 PM CET
For Locale GERMAN e.g.:
Heute, 26. Jan 2012 19:41 MEZ
For a date several days ago just:
Jan 22, 2012 07:41 PM CET
So, the [RELATIVE]-"prefix" should only appear if "available" (using ICU4J), otherwise we would like to see the exact date; we want do switch from a 12/24 hours representation automatically based on the locale
Patterns do not work since there is no identifier for that relative thing and also none for hh:mm with automatic 12/24 hours based on the locale.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看
Javadoc
与此您可以获得与区域设置相关的格式字符串。我不知道有任何合适的 API 可以在您的约会对象面前提供今天/明天 - Heute/Morgen。但您可以轻松地在前面提供星期几,例如 Wed 01/01/2010 10:00PM。
DateFormat 支持 12 小时(含 AM/PM)或一天 24 小时。
更新您的评论:再次检查 javadoc,DateFormat 支持 AM/PM 或全天时间,具体取决于区域设置。
生成
留下今天/明天的问题。 SimpleDateFormat 不提供此功能。如果您确实需要它,我会编写一个助手,它接受输入参数,包装 getDateTimeInstance().format() 调用,并在其前面添加今天/明天(如果日期匹配)。
Have a look at
Javadoc
With this you can get locale dependent format strings. I'm not aware of any proper API to provide Today/Tomorrow - Heute/Morgen in front of your date. But you could easily provide the day of week in front, like Wed 01/01/2010 10:00PM.
DateFormat supports both, 12 with AM/PM or 24 hours a day.
Update to your comment: Check the javadoc again, DateFormat supports AM/PM or full hours of day depending on locale.
generates
Leaves the today/tomorrow issue. SimpleDateFormat does not provide this feature. If you really need it, I'd write a helper that takes the input parameters, wraps the getDateTimeInstance().format() call and adds Today/Tomorrow in front of it, if the date matches.