我需要格式化日期,我正在使用SimpleDateFormat,但是当我尝试在任何Lollipop设备中使用它时,它都不会解析字符串,它会在索引3处抛出解析错误,好像它在期待11月的日期一样。 ,Dec,Mar格式,但四个M表示整月的字符串11月,12月,3月。

它可以在棉花糖中工作,但不能在棒棒糖中工作,没有在其他地方尝试过,有人知道如何解决此问题吗?

        SimpleDateFormat format = new SimpleDateFormat("MMMM dd yyyy hh:mm");
        Date nextDate = format.parse(mOverlord.getNextIrrigation().replaceAll("(?<=\\d)(,|st|nd|rd|th)", ""));
        Calendar c = Calendar.getInstance();


这是我得到的错误:

Unparseable date: "November 19 2016 21:54" (at offset 3)

最佳答案

区域设置是否设置为适当的值?如果可以选择的话,您可以强制使用美国区域设置,以下代码对我有用:

        SimpleDateFormat formatter = new SimpleDateFormat("MMMM dd yyyy hh:mm", Locale.US);
        Date x = formatter.parse("November 19 2016 21:54");

关于java - 是SimpleDateFormat在Android 5.1.1中不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40655732/

10-11 22:28
查看更多