日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務,提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了僅在某些設備上出現(xiàn)無法解析的日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我面臨著一個非常奇怪的問題。
解析此字符串2016-09-06 05:18:06.023 PM時,出現(xiàn)以下異常-java.text.ParseException: Unparseable date: "2016-09-06 05:18:06.023 PM" (at offset 24)

奇怪的是,發(fā)生此異常的設備是朋友的Nexus 5。但是,如果我在我的Nexus 5/其他幾個仿真器上調(diào)試相同的字符串,它工作得很好。

以下是我正在使用的代碼。SimpleDateFormat屬于java.text包。Date屬于java.util

    SimpleDateFormat formatGMT = new SimpleDateFormat("yyyy-MM-dd KK:mm:ss.SSS a");
    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();
     }

這是完整的堆棧跟蹤。

  # Crashlytics - plaintext stacktrace  Wed, 07 Sep 2016 03:37:44 GMT


# Platform: android

# Bundle Identifier: com.mypackage.app
# Issue #: 306

# Date: 2016-09-06T17:18:04Z
# OS Version: 6.0.1
# Device: Nexus 5
# RAM Free: 36.5%
# Disk Free: 11%

#0. Crashed: pool-3-thread-3: 0 0 0x0000000000000000
       at java.text.DateFormat.parse(DateFormat.java:579)
       at com.mypackage.app.MyService$16$1.execute(MyService.java:1670)
       at io.realm.Realm$1.run(Realm.java:1187)
       at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

--

Non-fatal Exception: java.text.ParseException: Unparseable date: "2016-09-06 05:18:06.023 PM" (at offset 24)
       at java.text.DateFormat.parse(DateFormat.java:579)
       at com.mypackage.MyService$16$1.execute(MyService.java:1670)
       at io.realm.Realm$1.run(Realm.java:1187)
       at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

#0. Crashed: pool-3-thread-3: 0 0 0x0000000000000000
       at java.text.DateFormat.parse(DateFormat.java:579)
       at com.mypackage.MyService$16$1.execute(MyService.java:1670)
       at io.realm.Realm$1.run(Realm.java:1187)
       at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

推薦答案

它可能會受到設備默認區(qū)域設置中的am/pm符號的影響,因此請嘗試使用下面的區(qū)域設置來解析它將對您有幫助的日期。

   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();
      }

這篇關于僅在某些設備上出現(xiàn)無法解析的日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:在某些 日期 解析 設備
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定