开发者

Exception in conversion of date formats

开发者 https://www.devze.com 2023-01-29 15:45 出处:网络
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\";

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

0

精彩评论

暂无评论...
验证码 换一张
取 消