问题描述:

I can't figure this out at all. I did:

int num = ((month-1)*30+day)%134;

//a,b,c are just for the Log

String a = String.valueOf(num);

String b = String.valueOf(month);

String c = String.valueOf(day);

Log.v("variables",a+","+b+","+c);

num ++;// don't want zero

String stringnum = String.valueOf(num);

Log.v("Index",stringnum);

month is todays month, day is today (i.e. december 31st = 12,31). In ANdroid this is taken from CALENDAR.

Now this program was working fine until today. Jan 1st. What happens is the DB searches for a string of index num, taken from the date. The problem isnt in the DB, its in this code.

Jan 1st is month=0, day = 1, naturally, but after mod 134 I get, courtesy of LogCat:

01-01 12:07:38.554: VERBOSE/variables(6917): -29,0,1

But 1mod134 != -29. I can't understand where -29 comes from.

网友答案:

When month is 0, (month-1)*30 is -30.

网友答案:

Sorry. I figured it out almost immediately after posting. month = 0, so month -1 = -1. I assumed month would start from 1 and go to 12, not zero to 11. Sorry for wasting anybody's time!

相关阅读:
Top