I searched all over the site, but I think I have a slightly different problem, and I can really help with it before I have heart failure or burn my computer.
I am dynamically generating a list of month names (in the form June 2011, July 2011) and obviously I want this to be locale sensitive: so I use a simple date format object like this:
//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
but if I do this:
String value=dtFormat.format(mCal.getTime());
this "should" return the localized version of the month name. In the Polish word "September" there is the word "Veresyan" - pay attention to the emphasis in Russian. However, all I get is "Get in?"
What am I doing wrong?
Thanks to everyone - now I admit that this is a problem with the presentation, but how can I safely "read" the result from dtFormat - I added some comments below ref using getBytes etc. - this worked in other situations, I just can’t seem to get access to the result of the string without messing it up
- FINAL Editing; for everyone who comes on this
The answer was made on the BalusC blog: http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html#DevelopmentEnvironment
Basically the DTformat object returned UTF-8 and automatically converted back to the default system character set when I read it in a string
so this code worked for me
new String(dtFormat.format(mCal.getTime()).getBytes("UTF-8"),"ISO-8859-1");
Thank you for help
source share