Why am I getting a ParseException when using SimpleDateFormat to format a date and then parse it?

前端 未结 3 747
南方客
南方客 2021-01-12 03:20

I have been debugging some existing code for which unit tests are failing on my system, but not on colleagues\' systems. The root cause is that SimpleDateFormat is throwing

3条回答
  •  太阳男子
    2021-01-12 03:35

    Check the LANG environment variable of your computer and of the remote computer.

    The date is parsed according to the locale, so 'Jul' works as July only if your LANG is set to english, otherwise a ParseException is raised.

    You can make a quick test by running export LANG="en_US.UTF-8" and then running your program.

    You can also set the locale programmatically, by using the following method: DateFormat.getDateInstance(int, java.util.Locale)

提交回复
热议问题