Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange Date Format behaviour with Xperia devices in Android
    primarykey
    data
    text
    <p>I'm facing a real issue with date parsing in Android. I'm receiving via JSON a date with dd/MM/yyyy HH:mm z format, all I need is to get the "localized" hour and minute and display it in my app. With my code everything is working fine on every device, but my clients reported me that they CAN'T see the timings in the app when using a Sony XPERIA device. They also told me that they had a XPeria device which couldn't display time, then they rooted it and everything started to work FINE. So I think it's something related so some strange implementation of the Date/simpledateformat/locale/timezone of sony's operative system. Here's my code.</p> <pre><code>getDateLocalized("18/06/2012 18:00 CEST","HH:mm"); public static String getDateLocalized(String match_date, String pattern) { String d = ""; String format = "dd/MM/yyyy HH:mm z"; SimpleDateFormat sdf = getSimpleDateFormat(); try { Date date = sdf.parse(match_date); sdf.setTimeZone(TimeZone.getDefault()); sdf.applyLocalizedPattern(pattern); d = sdf.format(date); sdf.applyLocalizedPattern(format); } catch (ParseException e) { e.printStackTrace(); } return d; } private static SimpleDateFormat getSimpleDateFormat() { String format = "dd/MM/yyyy HH:mm z"; if (simpledateformat == null) simpledateformat = new SimpleDateFormat(format, Locale.UK); return simpledateformat; } </code></pre> <p>I'm using a singleton pattern to retrieve the SimpleDateFormat object since its creation is really expensive, and I'm displaying a high number of timings at the same time. I'm using Locale.UK since the LANGUAGE of the input date is English.</p> <p>Big problem is that i DON'T have any sony xperia device to test it with :(</p> <p>Thanks in advice</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload