Reputation: 97
My SOAP service is deployed on a server with PDT timezone. I'm calling the service from my java (adf) code. The service has a mandatory parameter which takes date-time as parameter. Here is how, I'm calling it -
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(startDate);
GregorianCalendar c = new GregorianCalendar();
c.setTime(date);
sdate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
The SOAP service is supposed to store this date-time in the database which is also in the same server in PDT timezone. Now if I try to use this service from some other timezone, it converts it to PDT and then store in database.
I want the service to store the same time in database which I'm providing, instead of converting it. Any Idea, how to ignore the timezone.
Upvotes: 0
Views: 288
Reputation: 16209
I would suggest storing all your date times with the same (implicit) time zone in the database. Two common conventions are to use local time or Zulu time (UTC+0). After deciding on this convention you can store all your date times without adding the timezone information explicitly. (Postgress even has a separate setting for this).
As a consequence you have to convert all incoming date times to your database's implicit timezone before storing them. There are several patterns for this, like filters or date time handlers which you register with your ORM framework.
When returning date times from a service the common convention is to use Zulu time (appending a 'Z') or UTC (appending the timezone offset, for example '+02:00).
When returning directly to a user client like a browser or app it is also an option to localize the date time for the client. This means the client has to present its time zone, for example in a header field, as part of the user profile or on login (and stored in the HTTP session). Your component (e.g. a controller in an MVC application) must then apply this time zone to the date time from the database before adding it to the response.
Upvotes: 2