Android JodaTime:如何从DateTime对象获取ISO格式的时间?

Android JodaTime:如何从DateTime对象获取ISO格式的时间?,android,datetime,jodatime,Android,Datetime,Jodatime,我正在使用Joda的DTO: dateTimeObj = new DateTime(); 我想将此DTO转换为ISO格式的格式化字符串: 2016-03-06T11:30:00-05:00 我试过使用以下工具: dateTimeObj = new DateTime().toDateTimeISO(); 但是没有运气 我怎样才能用正确的方法来做呢?toDateTimeISO()已被弃用,请使用toDateTime() 此外: 请参见此处的模式语法: 首先,您需要使用而不是日期时间来访问您格

我正在使用Joda的DTO:

dateTimeObj = new DateTime();
我想将此DTO转换为ISO格式的格式化字符串:

2016-03-06T11:30:00-05:00
我试过使用以下工具:

dateTimeObj = new DateTime().toDateTimeISO();
但是没有运气

我怎样才能用正确的方法来做呢?

toDateTimeISO()
已被弃用,请使用
toDateTime()

此外:

请参见此处的模式语法:

首先,您需要使用而不是日期时间来访问您格式的时区

使用图表中定义的格式

您需要的格式为“YYYY-MM-DDTHH:MM:ss ZZZZ”。

您可以使用该格式获得不含毫秒部分的格式:

 DateTime dt = new DateTime();
 DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
 String str = fmt.print(dt);

嗯,我看不出“MMMM,yyyy”如何匹配期望的输出“2016-03-06T11:30:00-05:00”?@MenoHochschild它不匹配。我提供了一个简单的例子和细节链接。下面的评论中给出了适当的模式。
 DateTime dt = new DateTime();
 DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
 String str = fmt.print(dt);