Search code examples
androiddatetimejodatime

JodaTime : How to get ISO formatted time from DateTime object?


I'm getting DTO using the Joda:

dateTimeObj = new DateTime();

I would like to convert this DTO to formatted string in ISO format:

2016-03-06T11:30:00-05:00

I tried it using the:

dateTimeObj = new DateTime().toDateTimeISO();

But without the luck.

How can i do it in the right way please?


Solution

  • toDateTimeISO() is deprecated, use toDateTime() http://joda-time.sourceforge.net/apidocs/org/joda/time/Instant.html

    Also:

    DateTime dt = new DateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM, yyyy");
    String str = fmt.print(dt);
    

    See pattern syntax here: http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html