SimpleDateFormat “Unparseable date” Exception

后端 未结 8 1785
再見小時候
再見小時候 2020-12-20 16:55

I am trying to parse datetime string with SimpleDateFormat.parse() but I keep receiving Unparseable date exceptions.

Here is the date format I am trying

8条回答
  •  我在风中等你
    2020-12-20 17:46

    You first need to format the value in "2011-10-06T12: 00: 00-08: 00".

    Example: SimpleDateFormat dateParser = new SimpleDateFormat ("yyyy-MM-dd'T'HH: mm: ssZ");
    

    After, create the formating for formataction desired. Ex: SimpleDateFormat fmt = new SimpleDateFormat ("dd / MM / yyyy HH: mm: ss");

    and after make parse for date. Ex: Date date = dateParser.parse (dateFormat); and print of date formated.

    Below, one complete example.

    String dataStr = "2011-10-06T12: 00: 00-08: 00";
    SimpleDateFormat dataParser = new SimpleDateFormat ("dd / MM / yyyy HH: mm: ss", Locale.US);
    Date date;
    Try {
    date = dataParser.parse (dataStr);
    System.out.println (dateFormatter.format (date));
    
    } cath (ParseException e) {
    
    }
    

提交回复
热议问题