SimpleDateFormat throws ParseException With Error Offset 0

前端 未结 4 1214
情书的邮戳
情书的邮戳 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:09

    SimpleDateFormat is absolutely locale-sensitive. Certain fields, like hours and minutes, are locale-independent.

    SimpleDateFormat also supports localized date and time pattern strings. In these strings, the pattern letters described above may be replaced with other, locale dependent, pattern letters. SimpleDateFormat does not deal with the localization of text other than the pattern letters; that's up to the client of the class.

    Or, you can use the localization-friendly DateFormat#getDateInstance() factory method instead, since:

    public SimpleDateFormat(String pattern, Locale locale)

    Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the given locale. Note: This constructor may not support all locales. For full coverage, use the factory methods in the DateFormat class.

    Source: https://stackoverflow.com/a/5174712/2591612

提交回复
热议问题