You want to parse a localized date string to a Java Date.
As important as date formatting is, you have to be able to parse the formatted dates. Parsing a date is very similar to formatting the date. You just call the parse method on a DateFormat instance.
One important point is you need to specify the length of the DateFormat. This can be difficult to know in advance sometimes. You can wrap the parse attempt in a try catch to trap the ParseException and change the length of the DateFormat until you return a success.
To parse a date:
//Get a Locale
Locale chinese = new Locale("zh","CN");
//Get an instance of DateFormat.
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, chinese);
System.out.println(df.format(new Date()));
//Parse the date
//We need to handle the ParseException the parse method can throw
//The length specified in the DateFormat.getDateInstance method has to be the
//same as the string you are trying to parse, or you will get a ParseException in many cases.
try {
//parse(String str) returns a Date
Date date = df.parse("2008年11月30日 星期日");
System.out.println(date.toString());
} catch (ParseException e) {
e.printStackTrace();
}
The output:
2008年11月30日 星期日 Sun Nov 30 00:00:00 EST 2008