wood burning stoves 2.0*
The moose likes Web Services and the fly likes How can dateTime field format can be controlled ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How can dateTime field format can be controlled ?" Watch "How can dateTime field format can be controlled ?" New topic
Author

How can dateTime field format can be controlled ?

gcmahesh kumar
Greenhorn

Joined: Dec 05, 2010
Posts: 4
Hi,
I am storing a data with dateTime field with format as "2010-04-20T09:30:47.0+05:00" it get stored successfully but when i retrieve using webservice in response i get it as "2010-04-20T04:30:47.000Z". I want the response in the same way it is stored.
In javaClass i hv used GregorianCalendar as data Type.Is that cause for my problem ?


Thanks in Advance
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Mahesh,
xsd:dateTime is mapped to java.util.Calendar.
Your stubs on service and client side code should contain accordingly. You need to use java utility methods to format your dates, this has nothing to do with web services.

I see there is a mismatch in the times because of different time zones. You may need to use the right time zone to fix your problem.


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
gcmahesh kumar
Greenhorn

Joined: Dec 05, 2010
Posts: 4
Thanks for your reply Naren.
But i have 2 webservices one string based webservice and other Object based webservice.
In string based webservice i get the response in the way in wanted.Even for this i m using the same datatype(GregorianCalendar) for the same field. There it works fine but i m facing this problem only in Object based service where it is getting converted to the UTC Those time mismatch is because of this.
Technically they are equal but i dont want it (2010-04-20T09:30:47.0+05:00) to get converted to UTC(2010-04-20T04:30:47.000Z).
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you considered trying, or tried, XmlGregorianCalendar?
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Mahesh,
Ivan is right!

I am storing a data with dateTime field with format as "2010-04-20T09:30:47.0+05:00" it get stored successfully but when i retrieve using webservice in response i get it as "2010-04-20T04:30:47.000Z".

1. Map your first date to GregorianCalendar (as xsd:dateTime is mapped to java.util.Calendar), say this is "date1"
2. Create GregorianCalendar from your second date...

Now, check if "date1" and "date2" are equal.
gcmahesh kumar
Greenhorn

Joined: Dec 05, 2010
Posts: 4
Thanks for your reply Ivan and Naren.
This "((2010-04-20T09:30:47.0+05:00) to get converted to UTC(2010-04-20T04:30:47.000Z))" worked.
But i got a new problem from that.
when i am using this code
calendar = factory.newXMLGregorianCalendar(ConvertToDateFormat("2009-09-12 09:30:47.000000 +00:00")).toGregorianCalendar();
I get the output as 2009-09-12T09:30:47.000+00:00 But i need 2009-09-12T09:30:47.000000Z. i.e only if +00:00 is the time zone then Z should be appended.
Again this works fine with String based wsdl only object based wsdl is having this timestamp problem.

Thanks in Advance


 
 
subject: How can dateTime field format can be controlled ?
 
Similar Threads
date format problem
How to store arraylist in xml file
string to date conversion
Java Date
Java Calendar Dates