我试图让我的代码尽可能通用。我试图解析产品安装的安装时间。我将在产品中有两个文件,一个具有我需要解析的时间戳记,另一个文件告诉安装的语言。如何用Java或Perl解析Unicode字符的时间戳?
这是我如何解析时间戳
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());
}
}
我得到的输出是
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)
它抛出异常,并在当我打印它的结束,它显示了一些正确的日期。 ..虽然错了。我真的很感激,如果你能澄清我的这些疑问
如何解析有Unicode字符,如果这不是正确的方式时间戳?
如果解析失败,instTime如何能够保存某个日期,但错误? 我知道它的一些中国,韩国时间戳,所以我将语言环境设置为zh和ko,如下所示。即使这样,同样的错误再次出现
Locale = new Locale(“ko”);
Locale = new Locale(“ja”);
Locale = new Locale(“zh”);
我该怎么在Perl中做同样的事情?我不能使用Date :: Manip包;有没有其他方法?
..谢谢 – Ram 2010-05-14 08:57:40