I’m trying to make my code as generic as possible. I’m trying to parse install time of a product installation. I will have two files in the product, one that has time stamp I need to parse and other file tells the language of the installation.
This is how I’m parsing the timestamp
public class ts {
public static void main (String[] args){
String installTime = "2009/11/26 \u4e0b\u5348 04:40:54";
//This timestamp I got from the first file. Those unicode charecters are some Chinese charecters...AM/PM I guess
//Locale = new Locale();//don't set the language yet
SimpleDateFormat df = (SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT);
Date instTime = null;
try {
instTime = df.parse(installTime);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(instTime.toString());
}
}
The output I get is
Parsing Failed
java.text.ParseException: Unparseable date: "2009/11/26 \u4e0b\u5348 04:40:54"
at java.text.DateFormat.parse(Unknown Source)
at ts.main(ts.java:39)
Exception in thread "main" java.lang.NullPointerException
at ts.main(ts.java:45)
It throws exception and at the end when I print it, it shows some proper date… wrong though. I would really appreciate if you could clarify me on these doubts
-
How to parse timestamps that have unicode characters if this is not the proper way?
-
If parsing is failed, how could instTime able to hold some date, wrong though?
I know its some chinese,Korean time stamps so I set the locale to zh and ko as follows.. even then same error comes againLocale = new Locale(“ko”);
Locale = new Locale(“ja”);
Locale = new Locale(“zh”);
How can I do the same thing in Perl? I can’t use Date::Manip package; Is there any other way?
Your example datetime stamp is not conforming to CLDR, so we have to define a pattern manually.