A Calendar does have a time zone associated with it. And that appears to be what you are trying to do. So for the rest of this post, I will ignore the question about java.util.Date, since you don't seem to be using those here.
The "timezone" needed by XMLGregorianCalendar is an int, which is described in documentation as an offset in minutes. Presumably, this means how many minutes is the time zone off from GMT. Presumably you need to include any daylight savings effects here, since there's no separate way to specify this.
If you want to get the TimeZone from another Calendar and use that to specify the timezone for the XMLGregorianCalendar, you need to find the offset for that time zone. You're trying to use the SHORT static constant, which is an int, but other than that, has nothing at all to do with what you need here. I recommend using either the getOffset() or getRawOffset() methods here. The raw offset will not include daylight savings; if you need that, use getOffset. Note that these methods return an offset in milliseconds, and you need an offset in minutes. You will need to do some basic math to convert these.
1. From ui: 01/31/2013
2. To server: Thu Jan 31 00:00:00 PST 2013
4. If I used timezone getRawOffset which happened to -28800000, I got below exception:
5. If I used timezone SHORT which has 0 and it's OK. Is this by chance due to PST?
public static final int SHORT
A style specifier for getDisplayName() indicating a short name, such as "PST."
6. There is something I did not get. Thanks.
H Paul wrote:4. If I used timezone getRawOffset which happened to -28800000, I got below exception:
Mike Simmons wrote:Note that these methods return an offset in milliseconds, and you need an offset in minutes. You will need to do some basic math to convert these.
In other words, how many minutes are there in 28800000 milliseconds?
H Paul wrote:5. If I used timezone SHORT which has 0 and it's OK.
Well, it may compile and run without an obvious error, but is the result really accurate? I doubt it.
H Paul wrote:Is this by chance due to PST?
Not really. They mentioned PST in the JavaDoc as an example, saying that "PST" is the short name for "Pacific Standard Time". TimeZone.SHORT is a constant for "use the short form of the name", and TimeZone.LONG is a constant for "use the long form of the name". But you're using this constant in a completely different context where it makes no sense. It's probably better to just forget about this SHORT thing; it's just a distraction from what you need to understand here.