-1
我有以下代码:添加天日历不工作在Android
public void createWeeks(JSONArray TargetDays){
int helper, targetDayPos, curDayPos;
JSONArray dateContainer = new JSONArray();
JSONArray dateData = new JSONArray();
Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
Utilities dayConverter = new Utilities(getApplicationContext());
for(int i=0 ; i<TargetDays.length() ; i++){
try {
targetDayPos = dayConverter.getDayPosition(TargetDays.getString(i));
curDayPos = dayConverter.getCalenderDayPosition(dayOfWeek);
if (curDayPos > targetDayPos) {
helper = curDayPos - targetDayPos;
c.add(Calendar.DATE, -helper);
}
else if(targetDayPos > curDayPos){
helper = targetDayPos - curDayPos;
c.add(Calendar.DATE, helper);
}
dateData.put(c.get(Calendar.YEAR));
dateData.put(c.get(Calendar.MONTH)+1);
dateData.put(c.get(Calendar.DAY_OF_MONTH)+1);
Toast.makeText(getApplicationContext(),curDayPos+"\n"+targetDayPos,Toast.LENGTH_LONG).show();
dateContainer.put(dateData);
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
weekDayList.put("days",TargetDays);
weekDayList.put("dates", dateContainer);
} catch (JSONException e) {
e.printStackTrace();
}
}
我创建在一个星期在这里几天的阵列和他们的日期。但增加日子不起作用,最后我只是获得今天的日期。
你能做出[最小,完整,可验证的示例](http://stackoverflow.com/help/ mcve)?我相信这会对我们和你有很大的帮助。 –
我需要关于“添加”日历方法的帮助。它没有做任何事情。什么都没发生。我添加了几天后,然后我得到的时间它仍然是在添加之前的相同日期。 @Ole V.V. –
我对'Calendar.add()'非常有信心。我怀疑你的问题在别的地方。你尝试过调试器吗? –