Thread: [Pi] Date and Time Problem

Results 1 to 9 of 9
  1. #1 [Pi] Date and Time Problem 
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    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.

    Code:
    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;
    }
    Imports
    Code:
    import java.util.GregorianCalendar;
    import java.util.Calendar;
    The following problem is to do with the
    Code:
     public in getTimeOffline
    Its taking both dates 205 - 205 = 205 which isnt correct. Any help?
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    Bump paying 5m - 10m
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2010
    Posts
    498
    Thanks given
    41
    Thanks received
    84
    Rep Power
    54
    you problem i believe is in this
    public int getTodaysDate = month * 100 + day;
    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...

    EDIT: looking back what i think you should do is
    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;
    }
    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.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    Looks good trying it out.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    Bump.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    Still need help.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    Anyone?
    Reply With Quote  
     

  8. #8  
    Registered Member
    Xynth's Avatar
    Join Date
    May 2009
    Posts
    2,222
    Thanks given
    226
    Thanks received
    259
    Rep Power
    1155
    Nevermind, I am 100% wrong, one minute, I will look over your code.

    [EDIT]
    Actually, yes. I do believe your issue is with the
    Code:
    public int getTodaysDate = month * 100 + day;
    What that is doing is, multiplying the month by 100, then adding the day. That is wrong.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Jan 2011
    Posts
    309
    Thanks given
    9
    Thanks received
    26
    Rep Power
    28
    More specific?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Logging Date and Time (Useful for Chat, PM's etc.)
    By Simbioitic in forum Snippets
    Replies: 6
    Last Post: 04-28-2009, 02:12 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •