Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using SimpleDateFormat with format yyyy-MM-dd'T'HH:mm:ssZZZZZ. The expected output is "2014-08-26T13:00:14+03:00". However, "ZZZZZ" is only supported since Android 4.3.

Here is the result:

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

Note that the timezone 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 same timezone format in all version like above 4.3? Any suggestions?

like image 704
Dennis MP Avatar asked Sep 03 '14 05:09

Dennis MP


2 Answers

This is what I use, no version check:

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;
like image 193
Tony BenBrahim Avatar answered Oct 31 '22 21:10

Tony BenBrahim


you can try this format: ("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")

like image 29
duckk9vn Avatar answered Oct 31 '22 21:10

duckk9vn