5 Replies Latest reply: Jul 18, 2013 2:31 AM by 929859 RSS

    Error passing in a date object

    user8742475
      I'm calling Oracle CRM On Demand by generating a WS proxy of its WSDL file. There's a field of date datatype in CRMOD and in the java class, it accepts a Calendar object. Below is my code

      Here's my code

      1) I have a Date object
      2) I found a piece of code on the internet to get the WS 2.0 ISO8601 DateTime format. This method will format my Date object and return a String as below

      String dateString = "2011-09-08T00:00:00-0700-07:00";

      3)
      SimpleDateFormat dfISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
      Date dt= dfISO8601.parse(dateString);

      4)

      Calendar cal = Calendar.getInstance();
      cal.setTime(dt);

      5) customObject.setDStartDate(cal);

      but it kept saying

      "The value '11-09-08-07:00' cannot be converted to a date time value.(SBL-DAT-00359)"

      It looks like Calendar reverts back to the default date formatting which does not conform to XSD format.

      Do you have any idea?

      Thanks
        • 1. Re: Error passing in a date object
          tsuji
          String dateString = "2011-09-08T00:00:00-0700-07:00";
          This seems incorrect, maybe a typo after all?
          String dateString = "2011-09-08T00:00:00-07:00";
          For the parsing of date or datetime, you seem to using a deprecated method. In any case use javax.xml.bind.DatatypeConverter class to do the task, and then the TimeZone set to your desired one if you want to display it. In any case, pass the cal obtained from this?
          Calendar cal = javax.xml.bind.DatatypeConverter.parseDateTime(dateString);
          Also note that xs:date is actually constructed with an option of appending an extension of TimeZone data to iso8601, it is not exactly iso8601 to the letter.
          • 2. Re: Error passing in a date object
            user8742475
            Actually I have a Date object and instead of parsing it, how can I call a Web Service method that accepts a Calendar type?

            The date format of the WS I tried to call is in the form below

            For Web services v2.0, the data in SOAP requests conforms to XSD data formats.
            The XSD dateTime datatype has the format:
            yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
            For example:
            2009-10-10T12:00:00-05:00
            represents noon on 10th October 2002, Central Daylight Savings Time, which is equivalent to Eastern
            Standard Time in the US.
            As a further example:
            2009-10-09T17:00:00Z
            represents noon on 9th October 2009, UCT, which is equivalent to the GMT time zone.
            • 3. Re: Error passing in a date object
              tsuji
              First, you've to make up your mind in fixing what the question is otherwise every time it will end up "actually I have this rather than that... and need this rather than that...".
              Actually I have a Date object and instead of parsing it, how can I call a Web Service method that accepts a Calendar type?
              So you have a Date object. The service accepts a Calendar type? What kind of service would that be?
              For Web services v2.0, the data in SOAP requests conforms to XSD data formats.
              So that is a string of xs:date (date, not data?). Why would that be a Calendar type?

              If you start with a Date object and want to pass a string of xs:date format, you do this, as I'd practically suggested all the ingredients already.
              //dt being your date object
              Calendar cal=Calendar.getInstance();
              cal.setTime(dt);
              String s=javax.xml.bind.DatatypeConverter.printDate(cal);
              //you pass s to the soap message.
              • 4. Re: Error passing in a date object
                user8742475
                So you have a Date object. The service accepts a Calendar type? What kind of service would that be?
                It's Oracle CRM On Demand web service
                So that is a string of xs:date (date, not data?). Why would that be a Calendar type?
                I have a field in CRM On Demand of type Date. After I generated the Web Service Proxy from the WSDL, the setter method for that field is of type java.util.Calendar

                setDStartDate(java.util.Calendar)

                I have a Date object in my application and I want to pass it to this Date field in CRM On Demand.
                • 5. Re: Error passing in a date object
                  929859

                  Hi,

                  did you manage to query for your date type? Which date format did you use? I have a problem when I want to query using the modified date. It is a datetime field.

                  I tried every format but i always get an invalid date/time exception.

                  Kind regards,

                  thomas