0 Replies Latest reply on Nov 22, 2008 4:20 PM by Anthony Whitford

    Best Practices for Dates

    Anthony Whitford Newbie

      I have a web service that returns Dates. Imagine something simple like:

      @WebMethod
      Date getCurrentBusinessDate()
      


      In this case, I am only interested in a Date (not a Time or Date Time). This is by design because otherwise one might go down the road of considering Time Zones, etc. -- and that is not necessary for this case.

      When running something like this, we see a full date/time appear in the SOAP result. Sure, the time is zero/midnight, but it also mentions a time zone (which really shouldn't be there, but seems to be impossible to get rid of).

      By rights, I really only want to see a Date transmitted (like YYYY-MM-DD). In JPA, for example, I use a Date type but qualify it with a @Temporal annotation to clarify the TemporalType (Date, Time, DateTime). I see that JAXB has similar distinctions (xsd:date, xsd:time, xsd:dateTime).

      Is there a way to annotate the web method so the return value is clarified to be an xsd:date?


      Secondly... Is there a material difference between using java.util.Date vs. java.util.Calendar? (Is one really preferred over the other?) If I am writing Java-first Web Services, should I be using Date or Calendar to represent dates?


      Thanks for your help!