Apache Axis - Calendar instance that gets serialized to 0001-01-01T00:00:00.000Z

我与影子孤独终老i 提交于 2020-01-03 05:09:37

问题


I'm using Apache Axis to communicate with a web service written in .Net.

One of the functions in that WS has special handling when it encounters DateTime.MinDate (i.e. "0001-01-01"). Now, I'm trying to send this special value to the WS, but there seems to be no equivalent to DateTime.MinDate in Java.

As you probably know, Axis wraps xsd:dateTime into Calendar objects, so I tried sending new GregorianCalendar(1 ,1 ,1); but this didn't do the trick. I tried calendar.setTime(new Date(0)), I tried many more combinations, but nothing seems to get serialized as

<endDate xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</endDate>

which is what I need. Does anyone have any clue how can this be achieved?


回答1:


The following will create a GregorianCalendar object that will serialize to the equivalent of DateTime.MinValue.

GregorianCalendar gc=new GregorianCalendar(1,0,1);
gc.setTimeZone(TimeZone.getTimeZone("GMT-0"));

Note the following:

  • The month parameter is zero based, not 1 based.
  • GregorianCalendar defaults to the local time zone, therefore the timezone needs to be adjusted manually.


来源:https://stackoverflow.com/questions/7519800/apache-axis-calendar-instance-that-gets-serialized-to-0001-01-01t000000-000z

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!