http://en.wikipedia.org/wiki/Daylight_saving_time
In Java, there are two ways to create days. One method is using Calender object.
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR,2007);
c.set(Calendar.MONTH,9);
c.set(Calendar.DATE,31);
System.out.println(c.getTime());
c.add(Calendar.DATE,1);
System.out.println(c.getTime());
private List
Date date = dateRange.getStart().getTime();
Calendar c = Calendar.getInstance();
c.clear();
c.setTimeZone(dateRange.getStart().getTimeZone());
c.setTime(dateRange.getStart().getTime());
List
while (c.getTime().compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(c.getTime());
Calendar nextDate = (Calendar) c.clone();
nextDate.add(Calendar.DATE,1);
c = nextDate;
}
return dates;
}
This timezone don't work with daylight saving time. The other way is using Date object.
private List
Date date = dateRange.getStart().getTime();
List
while (date.compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(date);
Date nextDate = (Date) date.clone();
nextDate = DateUtils.addDays(nextDate, 1);
date = nextDate;
}
return dates;
}
This Date object time zone cater with daylight-saving time. In date object->cdate->daylightSaving parameter contains the time in milisecond that should add to the date for daylight-saving changes.
No comments:
Post a Comment