Java DATE Parsing

前端 未结 3 435
遥遥无期
遥遥无期 2020-12-11 20:01

I´m having a stupid problem with java.util.Date.

I have this line of code, but I don´t understand why this date is unparseable with this format.

相关标签:
3条回答
  • 2020-12-11 20:45

    Seems to be a Locale-related problem.

    If I set a French locale, the pattern does not work. If I set the Locale to be US in the SimpleDateFormat constructor, it does works.

    SimpleDateFormat dFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);

    0 讨论(0)
  • 2020-12-11 20:51

    If your system uses a locale other than English you need to use this constructor:

    SimpleDateFormat(DATE_FORMAT,Locale.ENGLISH);
    

    If this is not the problem, you should format a date using the same formatter and compare the output to your input string.

    0 讨论(0)
  • 2020-12-11 20:57

    I don't see anything wrong with this. It executes for me without error, and returns:

    Sat Dec 31 09:00:00 GMT 2011
    
    0 讨论(0)
提交回复
热议问题