Bump paying 5m - 10m
|
Im trying to add last logged in "days amount" this is the problem I'm having. I have added what I think should be right, but when I try to show the following it says 205 days. Which is incorrect. Here is my code.
ImportsCode:public int day = (Calendar.DAY_OF_MONTH); public int month = (Calendar.MONTH); public int year = (Calendar.YEAR); public int getTodaysDate = month * 100 + day; public int getTimeOffline = (getTodaysDate - startDate); public void giveDate() { startDate = getTodaysDate; }
The following problem is to do with theCode:import java.util.GregorianCalendar; import java.util.Calendar;
Its taking both dates 205 - 205 = 205 which isnt correct. Any help?Code:public in getTimeOffline
Bump paying 5m - 10m
you problem i believe is in this
could you tell me why your * 100 + day is ment to do? i dont see the point in adding 'day' and 'month * 100'... i cant see what how thats ment to equal what day it is...public int getTodaysDate = month * 100 + day;
EDIT: looking back what i think you should do is
this if you want the time server has ran just call getRunTime(); and it should come back almost always correct, the only problem i see is that there arnt an exact number of days in a month (average is 30) however u could also change that to match the numbers of days based on what month it is.. but whatever this is a rough outline of what it should look like, i know it could be better but it could also be worse.public int day = (Calendar.DAY_OF_MONTH);
public int month = (Calendar.MONTH);
public int year = (Calendar.YEAR);
public int[] getTodaysDate = { year, month, day};
public int[] startDate = { 0, 0, 0};
public void setStartDate() {//call this when server starts but ONLY CALL IT ONCE
startDate[0] = year;
startDate[1] = month;
startDate[2] = day;
}
public int getRunTime() {
int runTime = 0;
runTime += (getTodaysDate[0] - startDate[0]) * 365
runTime += (getTodaysDate[1] - startDate[1]) * 30
runTime += (getTodaysDate[2] - startDate[2]
return runTime;
}
Looks good trying it out.
Bump.
Still need help.
Anyone?
Nevermind, I am 100% wrong, one minute, I will look over your code.
[EDIT]
Actually, yes. I do believe your issue is with theWhat that is doing is, multiplying the month by 100, then adding the day. That is wrong.Code:public int getTodaysDate = month * 100 + day;
More specific?
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |