今天准备解析tomcat日志,发现tomcat日志里面的时间格式为:24/Jun/2015:09:22:09 +0800,试着用SimpleDateFormat解析,一直报错,后来才发现+0800时区的问题。
SimpleDateFormat formatter = new SimpleDateFormat(
"dd/MMM/yyyy:hh:mm:ss Z", Locale.ENGLISH);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
System.out.println(sdf.format(formatter.parse("24/Jun/2015:09:22:09 +0800")));
} catch (ParseException e1) {
e1.printStackTrace();
}
通过设置时区为Locale.ENGLISH解决。