java Joda ISODateTimeFormat序列化/反序列化
当我运行下面的测试时,它会打印出“2016-11-11”。这是怎么回事?如何让它打印我作为输入提供的DateTime字符串
import org.joda.time.DateTime;
import org.junit.Test;
public class Adapter2
extends XmlAdapter<String, DateTime>
{
public DateTime unmarshal(String value) {
return (org.joda.time.format.ISODateTimeFormat.dateTimeParser().parseDateTime(value));
}
public String marshal(DateTime value) {
return (org.joda.time.format.ISODateTimeFormat.dateTime().print(value));
}
@Test
public void test()
{
System.out.println(new Adapter3().marshal(new Adapter3().unmarshal("2016-11-12T00:00:00.000+08:00")));
}
}
# 1 楼答案
用
DateTime.parse()
代替ISODateTimeFormat.dateTimeParser().parseDateTime()
。或者使用DateTime.parse()
使用的东西: