SimpleDateFormat throws ParseException With Error Offset 0

前端 未结 4 1164
情书的邮戳
情书的邮戳 2021-01-23 04:19

What\'s wrong with the following code? It throws a ParseException with error offset 0.

final DateFormat df = new SimpleDateFormat(\"EEE MMM dd HH:mm:ss yyyy\");
         


        
4条回答
  •  盖世英雄少女心
    2021-01-23 05:15

    If you don't specify a Locale to the formatter when you construct it, it uses your default Locale which apparently doesn't spell days and months in English.

    So specify one to the formatter that does.

    final DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.UK);
    

提交回复
热议问题