Simpledateformat ParseException

前端 未结 3 356
慢半拍i
慢半拍i 2021-01-23 09:49

I need to change the input date format to my desired format.

String time = \"Fri, 02 Nov 2012 11:58 pm CET\";
SimpleDateFormat displayFormat = 
    new SimpleDat         


        
3条回答
  •  醉话见心
    2021-01-23 10:19

    First of All I must agree with @Eric answer.

    You just need to remove "CET" from your string of date.

    Here is sample code. Check it.

            String time = "Fri, 02 Nov 2012 11:58 pm CET";
            time = time.replaceAll("CET", "").trim();
            SimpleDateFormat displayFormat = 
                new SimpleDateFormat("dd.MM.yyyy, HH:mm");
            SimpleDateFormat parseFormat = 
                new SimpleDateFormat("EEE, dd MMM yyyy HH:mm aa");
            Date date = null;
            try {
                date = parseFormat.parse(time);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("output is " + displayFormat.format(date));
    

提交回复
热议问题