我正在尝试创建一个简单的议程类,以便为商店设置营业时间和关闭时间。我想根据一天设置不同的时间,所以我使用了 2 个这样的公历:
这是我的议程课程:
private SimpleDateFormat openingFormatter = new SimpleDateFormat("EEEE yyyy.MM.dd ' - Your shop is opening at' HH:mm");
private SimpleDateFormat closingFormatter = new SimpleDateFormat(" 'and closing at' HH:mm'.'");
private GregorianCalendar openingHoursCalendar = new GregorianCalendar();
private GregorianCalendar closingHoursCalendar = new GregorianCalendar();
private int totalDays=365;
Agenda(){
Calendar c = Calendar.getInstance();
if (openingHoursCalendar.isLeapYear(c.get(Calendar.YEAR))) {
totalDays++;
}
for(int d=1; d<=totalDays; d++) {
openingHoursCalendar.set(Calendar.DAY_OF_YEAR,d);
closingHoursCalendar.set(Calendar.DAY_OF_YEAR,d);
if(openingHoursCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY){
openingHoursCalendar.set(Calendar.HOUR_OF_DAY,8);
openingHoursCalendar.set(Calendar.MINUTE, 0);
closingHoursCalendar.set(Calendar.HOUR_OF_DAY,19);
closingHoursCalendar.set(Calendar.MINUTE, 30);
}
else {
openingHoursCalendar.set(Calendar.HOUR_OF_DAY,1);
openingHoursCalendar.set(Calendar.MINUTE, 1);
closingHoursCalendar.set(Calendar.HOUR_OF_DAY,1);
closingHoursCalendar.set(Calendar.MINUTE, 1);
}
}
}
public void printFullAgenda(){
openingHoursCalendar.add(Calendar.YEAR,-1);
closingHoursCalendar.add(Calendar.YEAR,-1);
for(int i=0; i<totalDays; i++){
openingHoursCalendar.add(Calendar.DAY_OF_YEAR,1);
closingHoursCalendar.add(Calendar.DAY_OF_YEAR,1);
System.out.print(openingFormatter.format(openingHoursCalendar.getTime()));
System.out.println(closingFormatter.format(closingHoursCalendar.getTime()));
}
}
所以我希望在周日(1:01)和其他日子的 8:00 / 19:30 打印相同的开放和关闭时间,但我得到的却是所有日子的时间完全相同(“你的商店是08:00 开放,19:30 关闭。”)。我真的不明白为什么。有人可以帮我解决这个问题吗?
谢谢