我在整个网站上搜索过,但我认为我有一个稍微不同的问题,在我出现心力衰竭或烧坏计算机之前可以真正做些帮助.
我动态生成月份名称列表(以2011年6月,2011年7月的形式),显然我希望这对区域设置敏感:因此我使用简单的日期格式对象,如下所示:
//the actual locale name is dependent on UI selection
Locale localeObject=new Locale("pl");
// intended to return full month name - in local language.
DateFormat dtFormat = new SimpleDateFormat("MMMM yyyy",localeObject);
//this bit just sets up a calendar (used for other bits but here to illustrate the issue
String systemTimeZoneName = "GMT";
TimeZone systemTimeZone=TimeZone.getTimeZone(systemTimeZoneName);
Calendar mCal = new GregorianCalendar(systemTimeZone); //"gmt" time
mCal.getTime(); //current date and time
Run Code Online (Sandbox Code Playgroud)
但如果我这样做:
String value=dtFormat.format(mCal.getTime());
Run Code Online (Sandbox Code Playgroud)
这个"应该"返回月份名称的本地化版本.在波兰语中,"九月"这个词是"Wrzesień" - 请注意n上的重音.然而我回来的只是"Wrzesie?"
我究竟做错了什么?
感谢所有 - 我现在接受这是一个演示问题 - 但我怎样才能安全地"读取"dtFormat的结果 - 我使用getBytes等在ref下面添加了一些注释 …