我想创建一个函数,在字符串数组中显示地点的开放时间,其中第一个条目是“异常”,其他(1-7)显示“day opentime:closetime”
但是显示错误的营业时间!
我展示了对象中的数据之一:
"created_at": "2012-01-03T13:31:53Z",
"updated_at": "2012-03-02T11:08:36Z",
"start_timestamp": 1325376000,
"exception_nl": "",
"exception_en": "",
"id": 447,
"end": "2012-12-31T00:00:00Z",
"enabled": true,
"start": "2012-01-01T00:00:00Z",
"season_openings": [
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Monday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3123,
"day": "Maandag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Tuesday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3124,
"day": "Dinsdag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Wednesday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3125,
"day": "Woensdag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Thursday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3126,
"day": "Donderdag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Friday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3127,
"day": "Vrijdag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Saturday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3128,
"day": "Zaterdag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
},
{
"endtime_timestamp": 946749600,
"created_at": "2012-01-03T13:31:53Z",
"endtime": "2000-01-01T18:00:00Z",
"closed": false,
"day_en": "Sunday",
"updated_at": "2012-03-02T11:08:36Z",
"id": 3129,
"day": "Zondag",
"starttime": "2000-01-01T10:00:00Z",
"starttime_timestamp": 946720800
}
您可以很清楚地看到开放时间有效的“季节”(在这种情况下为全年),然后有 7 个显示日期的对象。开始时间和结束时间是我需要的时间,这是标准日期。日、年、月无关紧要。
但是当我运行代码时,我的输出是:
07-25 10:46:17.720: I/openingstijden(31338): Maandag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Dinsdag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Woensdag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Donderdag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Vrijdag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Zaterdag: 21:50 - 21:50
07-25 10:46:17.720: I/openingstijden(31338): Zondag: 21:50 - 21:50
(这里我还没有对日期进行子串,对荷兰人感到抱歉,但这意味着周一到周日,所以效果很好)
但是所有的时间都是错误的。我不知道 21:50 是如何突然出现的。任何人的想法?下面是我的代码:
public String[] GetOpeningHours(JVenue venue, String language){
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
String[] oh= new String[8];
Date start,end;
JVenueSeasons seizoen = venue.venue_seasons.get(0); // get first, second ALWAYS enabled:false
if(language.equals("nld")){
oh[0]=seizoen.exception_nl; //exception eerste string uit array
for (int i=0; i<7;i++){
if(seizoen.season_openings.get(i).closed==true){
oh[(i+1)]= "gesloten";
}else{
start=seizoen.season_openings.get(i).starttime;
end=seizoen.season_openings.get(i).endtime;
calendar.setTime(start);
String starttijd= String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(calendar.get(Calendar.MINUTE));
calendar.setTime(end);
String eindtijd= String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(calendar.get(Calendar.MINUTE));
oh[(i+1)]= seizoen.season_openings.get(i).day.substring(0, 2)+ ": " + starttijd +" - "+eindtijd;
}
}
}else{
oh[0]=seizoen.exception_en; //exception eerste string uit array
for (int i=0; i<7;i++){
if(seizoen.season_openings.get(i).closed==true){
oh[(i+1)]= "closed";
}else{
start=seizoen.season_openings.get(i).starttime;
end=seizoen.season_openings.get(i).endtime;
calendar.setTime(start);
String starttijd= String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(calendar.get(Calendar.MINUTE));
calendar.setTime(end);
String eindtijd= String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(calendar.get(Calendar.MINUTE));
oh[(i+1)]= seizoen.season_openings.get(i).day_en.substring(0, 2)+ ": " + starttijd +" - "+eindtijd;
}
}
}
return oh;
}
}