Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Clearing second in Calendar also clears dst offset

806707Nov 1 2010 — edited Nov 12 2010
Why gets the dst offset cleared when I clear seconds in a Calendar instance?

import java.util.Calendar;


public class WinterTime {

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(1288485034375L);
        int dstOffset = calendar.get(Calendar.DST_OFFSET);
        System.out.println(calendar.getTimeInMillis() + " = " + calendar.getTime() + " + " + calendar.get(Calendar.DST_OFFSET));
        calendar.clear(Calendar.SECOND);
        System.out.println(calendar.getTimeInMillis() + " = " + calendar.getTime() + " + " + calendar.get(Calendar.DST_OFFSET));
        calendar.set(Calendar.DST_OFFSET, dstOffset);
        System.out.println(calendar.getTimeInMillis() + " = " + calendar.getTime() + " + " + calendar.get(Calendar.DST_OFFSET));
    }

}
Output:

1288485034375 = Sun Oct 31 02:30:34 CEST 2010 + 3600000
1288488600375 = Sun Oct 31 02:30:00 CET 2010 + 0
1288485000375 = Sun Oct 31 02:30:00 CEST 2010 + 3600000

Edited by: 803704 on Nov 8, 2010 9:12 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2010
Added on Nov 1 2010
34 comments
632 views