Subject | Re: [Firebird-Java] Re: time zone problem |
---|---|
Author | Roman Rokytskyy |
Post date | 2004-07-29T18:03:30Z |
> I think the bug is the use of "Calendar.getInstance().getTimeZoneSounds logical, but I'm not yet convinced that this is correct. Consider the
> ().getRawOffset());" and the subtraction since that line of code is
> getting the local machine's time zone to perform the time zone
> conversion calculation (which it should *never* do) … shouldn't this
> just simply be:
> long time = value.getTime() + cal.getTimeZone().getRawOffset();
> This simply take the UTC and addes (or subtracts if negative) the
> passed calendar object's offset value.
> ??thoughts??
following code:
Calendar gmt = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
Calendar cet = Calendar.getInstance(TimeZone.getTimeZone("CET"));
gmt.set(Calendar.YEAR, 2004);
gmt.set(Calendar.MONTH, Calendar.JULY);
gmt.set(Calendar.DAY_OF_MONTH, 29);
gmt.set(Calendar.HOUR_OF_DAY, 19);
gmt.set(Calendar.MINUTE, 31);
gmt.set(Calendar.SECOND, 25);
gmt.set(Calendar.MILLISECOND, 15);
cet.set(Calendar.YEAR, 2004);
cet.set(Calendar.MONTH, Calendar.JULY);
cet.set(Calendar.DAY_OF_MONTH, 29);
cet.set(Calendar.HOUR_OF_DAY, 20);
cet.set(Calendar.MINUTE, 31);
cet.set(Calendar.SECOND, 25);
cet.set(Calendar.MILLISECOND, 15);
long gmtTime = gmt.getTimeInMillis();
long cetTime = cet.getTimeInMillis();
System.out.println("UTC time is " + gmt.getTime().toString());
System.out.println("CET time is " + cet.getTime().toString());
System.out.println("UTC time is " + gmtTime +
", CET time is " + cetTime +
", difference is " + (cetTime - gmtTime));
In theory, if getTimeMillis() returns UTC time there should be no difference
between CET time converted into UTC and UTC. However it prints the -3600
seconds difference - UTC time for some reason is 1 hour greater when
converted to string. Note that when in CET is 20:00, in UTC that's 19:00, so
I think I have set correct values to the calendar.
How do you interpret these results?
Roman