Search code examples
androidtimezonejodatimeiso8601

Android time in iso 8601


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?


Solution

  • 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.