Exception in conversion of date formats
I am trying to convert the date format from "dow mon dd hh:mm:ss zzz yyyy" to "MM/dd/yyyy"
String inputPattern = "dow mon dd hh:mm:ss zzz yyyy";
String outputPattern = "MM/dd/yyyy";
SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);
Date date=inputFormat.parse("Tue Dec 07 15:59:03 IST 2010");
System.out.println("Date : "+outputFormat.format(date));
But While running the above code the following exception occurs
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'o'
at java.text.SimpleDateFormat.compile(S开发者_如何学GoimpleDateFormat.java:769)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:501)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:476)
at com.kpub.web.bean.action.ReportGeneration.main(ReportGeneration.java:198)
What may be the problem?
Maybe you can use for input pattern as;
EEE MMM dd HH:mm:ss zzz yyyy
From Java Manual
精彩评论