Using SimpleDateFormat "ZZZZZ" (+03: 00) for timezone before Android 4.3

I am using SimpleDateFormat

with the format yyyy-MM-dd'T'HH:mm:ssZZZZZ

. The expected result is "2014-08-26T13: 00: 14 + 03: 00". However, "ZZZZZ" is only supported since Android 4.3.

Here's the result:

  • Above 4.3: 2014-08-26T13: 00: 14 + 03: 00
  • Below 4.3: 2014-08-26T13: 00: 14 + 0300

Please note that the time zone section is different (03:00 vs 0300)

I have looked at this bug report: http://code.google.com/p/android/issues/detail?id=73209 .

Is it possible to get the same timezone format in the whole version as above 4.3? Any suggestions?

+4


source to share


3 answers


This is what I am using.



private static final SimpleDateFormat DATEFORMATRFC3339 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.ENGLISH);

public static String formatrfc3339(Date date) {
    if(VersionUtils.isJellyBeanMR2Compatible()) {
        return DATEFORMATRFC3339.format(date);
    }
   return DATEFORMATRFC3339.format(date).replaceAll("(\\d\\d)(\\d\\d)$", "$1:$2");
}

      

+1


source


This is what I am using, without version checking:



String result = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZZZZZ").format(calendar.getTime());
//fix up for older Android where ZZZZZ does not include colon
if (!result.substring(result.length() - 3).startsWith(":")) {
    result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
        }
return result;

      

0


source


You can try this format: ("yyyy-MM-dd'THH: mm: ss. SSSXXX")

0


source







All Articles