Parsing a date with short month without dot

后端 未结 6 1722
情书的邮戳
情书的邮戳 2020-12-10 02:19

I have a String that represents a date in French locale : 09-oct-08 :

I need to parse that String so I came up with this SimpleDa

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 02:37

    String format2 = "dd-MMM-yy";
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat sdf = new SimpleDateFormat(format2);
    System.out.println(sdf.format(date));
    

    Outputs 28-Oct-09

    I don't see any dots sir. Have you tried re-checking your prints? Maybe you accidentally placed a . beside your MMM?


    You're getting java.text.ParseException: Unparseable date: "09-oct-08" since "09-oct-08" does not match the formatting of Locale.FRENCH either use the default locale(US I think) or add a . beside your oct

提交回复
热议问题