SimpleDateFormat behaviour change in Android Marshmallow

后端 未结 1 1311
死守一世寂寞
死守一世寂寞 2021-01-12 19:35

I have encountered an issue with date formatting on Android 6.0, Marshmallow. The code throwing the exception noted below is a pure-Java library (built separately) which my

相关标签:
1条回答
  • 2021-01-12 19:59

    The UK Locale appears to have had its definitions of "am" and "pm" altered.

    In Marshmallow the UK Locale now has "am" represented as "a.m." and "pm" by "p.m."

    String record = "2015-10-23 Fri 10:59 p.m. BST   3.60 meters"
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd E hh:mm aa", Locale.UK);
    
    // note the length is 25 now, not 23... 
    Date eventDate = dateFormat.parse(StringUtils.substring(record, 0, 25).trim());
    

    I can't offer an explanation why, but the US Locale works with am/pm and the UK with a.m./p.m.

    Edit

    It appears that as part of the Locale updates in March 2015, the en_gb locale had its am/pm definitions replaced. source diff

    0 讨论(0)
提交回复
热议问题