L
lordy
I can create a SimpleDateFormatter with the correct timeZone.
If but when I use format(Date D) it always displays the date
using daylight savings (which are currently in force in the UK),
(eg new Date(0) has 'HH' set to '01' when formatted.
See example below:
Do I need to do test each dates inDaylightTime() against the current system time's
inDaylightTime() to work
out how to display the time using daylight savings applicable at
that time (rather than the current system time)
ie doesnt the SimpleDateFormat.format() method have an option to do this?
Example:
import java.util.Date;
import java.text.SimpleDateFormat;
public class D {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm");
Date dt = new Date();
//Should be London time - daylight savings
System.out.println(sdf.getTimeZone());
dt.setTime(0);
System.out.println(sdf.format(dt));
}
}
Output:
sun.util.calendar.ZoneInfo[id="GB",offset=0,dstSavings=3600000,
useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone
[id=GB,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,
startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,
startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,
endTime=3600000,endTimeMode=2]]
70-01-01 01:00 <<< Expected 70-01-01 00:00
Lordy
If but when I use format(Date D) it always displays the date
using daylight savings (which are currently in force in the UK),
(eg new Date(0) has 'HH' set to '01' when formatted.
See example below:
Do I need to do test each dates inDaylightTime() against the current system time's
inDaylightTime() to work
out how to display the time using daylight savings applicable at
that time (rather than the current system time)
ie doesnt the SimpleDateFormat.format() method have an option to do this?
Example:
import java.util.Date;
import java.text.SimpleDateFormat;
public class D {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm");
Date dt = new Date();
//Should be London time - daylight savings
System.out.println(sdf.getTimeZone());
dt.setTime(0);
System.out.println(sdf.format(dt));
}
}
Output:
sun.util.calendar.ZoneInfo[id="GB",offset=0,dstSavings=3600000,
useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone
[id=GB,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,
startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,
startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,
endTime=3600000,endTimeMode=2]]
70-01-01 01:00 <<< Expected 70-01-01 00:00
Lordy