Unparseable date

Dear Java Gurus,

Locale theLocale = Locale.GERMANY;

Calendar calendar = Calendar.getInstance(theLocale);

Date d = calendar.getTime();

System.out.println("Supposedly localised string: "+ d.toLocaleString());

produces:

Supposedly localised string: Mar 23, 2004 10:02:31 PM

Which seems to make no sense, while there are no pm's in german and mar is not short for Maerz.

The thing is I switched my entire operating system language to English and since then to make things even more fun I get the following error later,

java.text.ParseException: Unparseable date: "Mar 23, 2004 10:01:17 PM"

hmm, watcha lot think? what's my best work around?

thanks

kent

[736 byte] By [kentkent] at [2007-9-30 4:08:53]
# 1

No wonder: the Date object is not aware which Calendar it was obtained from.

toLocaleString() is deprecated anyway

import java.text.*;

import java.util.*;

public class u {

public static void main(String argv[]) {

Locale theLocale = Locale.GERMANY;

DateFormat df0=DateFormat.getDateInstance(DateFormat.LONG,theLocale);

DateFormat df1=DateFormat.getDateInstance(DateFormat.SHORT,theLocale);

//Calendar calendar = Calendar.getInstance(theLocale);

Date d = new Date();

System.out.println(df0.format(d));

System.out.println(df1.format(d));

}

}

$ java u

24. Ma:rz 2004

24.03.04

BIJ001 at 2007-6-29 17:50:55 > top of Java-index,Administration Tools,Sun Connection...
# 2
that did the trick! thanks a bunch.
kentkent at 2007-6-29 17:50:55 > top of Java-index,Administration Tools,Sun Connection...