2010-08-23 53 views

回答

0

如果我看到这个问题很好,你想与MessageFormat这样的显示消息:

Object[] arguments = { 
    new Integer(7), 
    new Date(System.currentTimeMillis()), 
    "a disturbance in the Force" 
}; 

String result = MessageFormat.format(
     "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", 
     arguments); 

(来自javadoc的示例)

我检查了的来源,我看到getLocale()对于整个消息是很常见的。您无法为参数制作独特的参数。

为什么不用带格式的日期字符串本身生成参数?像这样:

Object[] arguments = { 
    new SimpleDateFormat("yyyyy.MMMMM.dd GGG hh:mm aaa", Locale.UK).format(new Date()) 
}; 

String result = MessageFormat.format(
     "This is the date format which I always want independently of the locale: {1} ", 
     arguments); 

format方法的第一个参数可能来自本地化属性文件。

+0

该问题更多地取决于不同用户想要看到的资源,而不是关于如何使用硬编码区域设置格式化日期。 simpleDateFormat将始终使用默认的语言环境。但文本将使用特定的资源包。谢谢 – Marc 2010-08-24 14:34:21

相关问题