开发者

htc g7 os2.2 can't support the symbol 'a' of SimpleDateFormat

I found htc g7 can't support the symbol 'a' of SimpleDateFormat. So I can't parse date expediently. For example: the code: *

    Simp开发者_运维知识库leDateFormat sdf2 = new SimpleDateFormat("MM/dd/yy hh:mm a");

    String d2 = "12/15/10 6:30 PM";  

    try{
        sdf2.parse(d2);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
}
*

Test in simulator, that's ok. But run on my phone, It will occur the ParseException.

My phone HTC G7 os2.2


Possibly a locale issue? Try explicitly setting the locale in your code above by using...

SimpleDateFormat sdf2 = new SimpleDateFormat("MM/dd/yy hh:mm a", Locale.US);

...just to test to see if it works on the phone.

From "Be wary of the default locale" http://developer.android.com/reference/java/util/Locale.html#default_locale

A common mistake is to implicitly use the default locale when producing output meant to be machine-readable. This tends to work on the developer's test devices but fail when run on a device whose user is in a less conventional locale.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜