P
Philipp
Hello,
In my Locale there is Daylight Savings Time (DST) in effect. I would
like to get the time of the day without the DST (ie, the hour as
indicated by the sun position). To do this I use Calendar and set the
DST_OFFSET to 0. But that doesn't work. See example code below. What am
I doing wrong?
Thanks Phil
-- SSCCE --
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public class TestCalendar {
public static void main(String[] args) {
Date now = new Date(1214127677625L);
System.out.println(now);
Calendar cal = new
GregorianCalendar(TimeZone.getTimeZone("Europe/Zurich"));
cal.setTimeInMillis(now.getTime()); // setting both calendars to now
System.out.println("current DST: " + cal.get(Calendar.DST_OFFSET));
System.out.println(" With DST: " + cal.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.DST_OFFSET, 0); // putting DST to 0
System.out.println("new DST: " + cal.get(Calendar.DST_OFFSET));
System.out.println(" Without DST: " + cal.get(Calendar.HOUR_OF_DAY));
}
}
// Prints
Sun Jun 22 11:41:17 CEST 2008
current DST: 3600000
With DST: 11
new DST: 0
Without DST: 11
// Expected
Sun Jun 22 11:41:17 CEST 2008
current DST: 3600000
With DST: 11
new DST: 0
Without DST: 10
In my Locale there is Daylight Savings Time (DST) in effect. I would
like to get the time of the day without the DST (ie, the hour as
indicated by the sun position). To do this I use Calendar and set the
DST_OFFSET to 0. But that doesn't work. See example code below. What am
I doing wrong?
Thanks Phil
-- SSCCE --
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public class TestCalendar {
public static void main(String[] args) {
Date now = new Date(1214127677625L);
System.out.println(now);
Calendar cal = new
GregorianCalendar(TimeZone.getTimeZone("Europe/Zurich"));
cal.setTimeInMillis(now.getTime()); // setting both calendars to now
System.out.println("current DST: " + cal.get(Calendar.DST_OFFSET));
System.out.println(" With DST: " + cal.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.DST_OFFSET, 0); // putting DST to 0
System.out.println("new DST: " + cal.get(Calendar.DST_OFFSET));
System.out.println(" Without DST: " + cal.get(Calendar.HOUR_OF_DAY));
}
}
// Prints
Sun Jun 22 11:41:17 CEST 2008
current DST: 3600000
With DST: 11
new DST: 0
Without DST: 11
// Expected
Sun Jun 22 11:41:17 CEST 2008
current DST: 3600000
With DST: 11
new DST: 0
Without DST: 10