Android time in iso 8601

Ranco picture Ranco · Nov 22, 2012 · Viewed 19.5k times · Source

using android and joda time lib - the I am trying to convert the user's timezone in order to format it later to : 2012-11-12T21:45:00+02:00 for example.

DateTimeZone zone = DateTimeZone.forID( TimeZone.getDefault().getID());

the above code fails - anyone know how can I take "Europe/London" (Timezone.getID) and convert it to an offset so I can put it in ISO 8601 format?

Answer

Luis picture Luis · Nov 22, 2012

If I have correctly understood your objective you can use directly the SimpleDateFormat class.

Example code:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.UK);
String formattedDate = sdf.format(new Date());

You can see documentation in SimpleDateFormat

Regards.