Reputation: 13061
i'm having a strange issue.
Using eclipse i generate a stub using a wsdl.
The stub generated accept as parameter a java object in which i need to set a Calendar.
i've got a date in format "yyyy-MM-dd" for example:
"2015-02-03"
To set Calendar to pass to the stub i use:
String arrival[] = "2015-02-03".split("-");
Calendar calendar = Calendar.getInstance();
calendar.set(Integer.parseInt(arrival[0]), Integer.parseInt(arrival[1])-1, Integer.parseInt(arrival[2]),0,0,0);
And to call stub:
StubBean bean = new StubBean(calendar,...);
stub.method(bean);
String xml_request = stub._getCall().getMessageContext().getRequestMessage().getSOAPPartAsString();
System.out.println(xml_request);
If i print the soap xml request i notice that the date is :
<ArrivalDate>2015-02-02T23:00:00.244Z</ArrivalDate>
So one hour before the date i provide.
How can i solve that strange issue?
Thanks!
Upvotes: 0
Views: 1068
Reputation: 25439
Calendar calendar = Calendar.getInstance();
This is going to produce a calendar object using the host computer's default timezone.
<ArrivalDate>2015-02-02T23:00:00.244Z</ArrivalDate>
This time is in UTC (the "Z" at the end means "Zulu", aka UTC).
You've indicated the computer is using the time zone for Paris, which is one hour ahead of UTC. In other words, when it's Midnight, Feb. 3 in Paris, it's 23:00, Feb 2 in UTC.
You can initialize the calendar to use UTC instead:
TimeZone tzUTC = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(tzUTC);
Upvotes: 2