Calendar.DST_OFFSET field being cleared unexpectedly

J

Jim Garrison

Given the following class:

public class TestDate
{
public static void main(String[] args)
{
GregorianCalendar c = new GregorianCalendar();
System.out.println(c.get(Calendar.DST_OFFSET));
c.set(Calendar.YEAR,2006);
System.out.println(c.get(Calendar.DST_OFFSET));
c.set(2006, Calendar.DECEMBER, 31);
System.out.println(c.get(Calendar.DST_OFFSET));
}
}

Can someone explain why the output (when run in the CDT
timezone) is:

3600000
3600000
0

It appears that the set(int,int,int) call clears the DST_OFFSET field,
even though the API explicitly states:

public final void set(int year,
int month,
int date)

Sets the values for the calendar fields YEAR, MONTH, and
DAY_OF_MONTH. Previous values of other calendar fields are retained.
If this is not desired, call clear() first.

What am I missing?

BTW, this is with Sun JDK 1.5.0_10.
 
J

Jim Garrison

Jim said:
Given the following class:

public class TestDate
{
public static void main(String[] args)
{
GregorianCalendar c = new GregorianCalendar();
System.out.println(c.get(Calendar.DST_OFFSET));
c.set(Calendar.YEAR,2006);
System.out.println(c.get(Calendar.DST_OFFSET));
c.set(2006, Calendar.DECEMBER, 31);
System.out.println(c.get(Calendar.DST_OFFSET));
}
}

Can someone explain why the output (when run in the CDT
timezone) is:

3600000
3600000
0

It appears that the set(int,int,int) call clears the DST_OFFSET field,
even though the API explicitly states:

public final void set(int year,
int month,
int date)

Sets the values for the calendar fields YEAR, MONTH, and
DAY_OF_MONTH. Previous values of other calendar fields are retained.
If this is not desired, call clear() first.

What am I missing?

BTW, this is with Sun JDK 1.5.0_10.

Never mind... I was reading UTC_OFFSET for DST_OFFSET. My bad....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top