2010-08-23 62 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