0

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?

kaqqao
  • 12,984
  • 10
  • 64
  • 118
  • Similar question: http://stackoverflow.com/questions/4006186/java-equivalent-of-datetime-minvalue-datetime-today – Peter O. Sep 22 '11 at 18:57
  • Seen it, but it's not really that similar... That one asks for a Java equivalent in general, which I know how to get (new GregorianCalendar(1 ,1 ,1);), but I need something that will be serialized to SOAP xsd:dateTime in the same way as DateTime.MinDate (i.e. 0001-01-01T00:00:00.000Z) which the afore mentioned solution doesn't seem to do. – kaqqao Sep 24 '11 at 20:30

1 Answers1

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.
Peter O.
  • 32,158
  • 14
  • 82
  • 96