java.text.ParseException: Unparseable date on some devices only

前端 未结 1 680
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 12:55

I\'m facing a very bizarre issue. While parsing this string 2016-09-06 05:18:06.023 PM I get the following exception - java.text.ParseException: Unparseable d

相关标签:
1条回答
  • 2021-01-25 13:02

    It may be possible it can be affected by Symbols For am/pm in device default locale, so try to use locale as below to parse date it will help you.

       SimpleDateFormat formatGMT = new SimpleDateFormat("yyyy-MM-dd KK:mm:ss.SSS a", Locale.US);
    
          formatGMT.setTimeZone(TimeZone.getTimeZone("GMT"));
    
          try 
          {
                 date = formatGMT.parse("2016-09-06 05:18:06.023 PM");
          } 
          catch (ParseException e)
          {
                 Crashlytics.log(Log.ERROR, "DB Insertion error", e.getMessage().toString());
                 Crashlytics.logException(e);
                 e.printStackTrace();
          }
    
    0 讨论(0)
提交回复
热议问题