0

I have two SOAP and Rest webservices both has a field called CreatedDate. I am getting date from the DB and setting to the Date field of Java class. There are two different Output object for each service. But when I access these services from the SOAP UI, I am getting different format of time.

From SOAP: 2014-06-02T03:05:34-05:00
From Rest: 2014-06-02T08:05:34Z

Both are same time coming from same DB cell. But format is different. I am using CXF for both WS with spring. I want both in first format.

Thanks

1 Answers1

1

But format is different.

Not really. They're both using the date/time format in RFC 3339 / ISO-8601, as per the W3C XML schema recommendation, which expresses an offset from UTC as well as the local date/time. Z is used as a UTC offset of 0.

Those are different values in terms of the time zone offset, but represent the same instant in time. One representation expresses this in UTC, another in a time zone which is 5 hours behind UTC at that instant. (Contrary to the terminology used in various standards, the "-05:00" doesn't actually identify a time zone; it only shows the offset from UTC at that instant. A "real" time zone is effectively a function from any UTC instant to the local time at that instant.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • FYI, RFC 3339 is based on ISO 8601 for which you can read [this explanatory Wikipedia page](http://en.wikipedia.org/wiki/ISO_8601). – Basil Bourque Jun 02 '14 at 15:56
  • 1
    Why do you say "interpreting it incorrectly"? The two strings represent the same moment. One is correctly adjusted to UTC. – Basil Bourque Jun 02 '14 at 16:00
  • @BasilBourque: Ah - had missed that they were different hours in the text (which is bizarre, as I specifically looked for that). Will edit. – Jon Skeet Jun 02 '14 at 16:04
  • My guess is that the original date-time was adjusted to UTC when stored in the database, as it should be in good practice. The Rest service is reporting this value directly. The Soap service on the other hand is applying an offset or time zone to adjust for a locality perhaps in Chicago US, Panama, or such. – Basil Bourque Jun 02 '14 at 16:41
  • @BasilBourque: Possibly. Of course it could be that the original offset was relevant and was even stored in the database, and that the Rest service is *inappropriately* converting it to UTC. It depends on the context :) – Jon Skeet Jun 02 '14 at 16:45
  • How can I make Rest service to display the date as Soap service is doing? Is there any configuration to change? – user3699868 Jun 03 '14 at 04:44
  • Well we have no idea what's implementing the Rest service, which makes it hard to say - but unless the offset is really important to you, any decent client *should* treat the values the same way. (Or rather, it should parse them as the same instant in time.) – Jon Skeet Jun 03 '14 at 05:39
  • @JonSkeet: We are using CXF for both Rest and Soap. Client is reading it as String. So when they read the field from Soap and Rest there is difference. I want to remove that discrepancy. – user3699868 Jun 03 '14 at 06:22
  • You can easily convert the values using Joda-Time. Search for "Joda" for many examples. `new DateTime( soapResult, DateTimeZone.UTC ).toString()` – Basil Bourque Jun 03 '14 at 07:13
  • @user3699868: If the client is *just* reading it as a string, they're doing the wrong thing. That's like trying to adjust your XML on the grounds of a client which cares whether you have `` or ``. The client *should* be parsing the value according to the schema. More importantly, is the offset relevant in your situation? If it is, then that *is* a significant difference which you should look into. If it just happens to be from your system local time zone, then it's not giving any useful information. – Jon Skeet Jun 03 '14 at 07:15
  • I have same issue like http://stackoverflow.com/questions/13803391/serialize-date-in-a-json-rest-web-service-as-iso-8601-string this post. But I have implemented the MessageBodyWriter. I gave the date format as ISO8601DateFormat. But I want the format as Soap response. – user3699868 Jun 03 '14 at 08:20
  • @user3699868: Again, that doesn't give us any information about why the client would have a problem with a perfectly valid XML representation of a date/time. – Jon Skeet Jun 03 '14 at 08:26
  • Earlier we had only SOAP. Now we have Rest as well. These services are being used at GUI. So at GUI side they are using Time with offset as String. Now they are consuming the Rest they want same format with time offset. So we are asked to fix it at service side. – user3699868 Jun 03 '14 at 08:37
  • @user3699868: I would personally push back. You're providing a perfectly valid timestamp... if the offset doesn't provide any relevant information (you still haven't clarified that) then it's just the client side being lazy. – Jon Skeet Jun 03 '14 at 09:06