add up in time

Discussion in 'Jiggy Runtime Development' started by rob spriggs, Jul 10, 2008.

  1. rob spriggs

    rob spriggs New Member

    Joined:
    Jan 26, 2008
    Messages:
    28
    Likes Received:
    0
    hi, i am going to try and make a new app that will add up in time,

    for example if i put i could add 240 hours 23 minutes and 14 hours 59 minutes together.

    unfortuantly i havnt got a clue where to start because as soon as the minutes goes over 60 it will need to plus 1 hour and start again at 0, can anyone please help me get started in this, thanks

    Rob
  2. pabloppp

    pabloppp New Member

    Joined:
    Feb 21, 2008
    Messages:
    53
    Likes Received:
    0
    try this:

    if (minutes == 60)
    {
    minutes = 0
    hour += 1
    }
  3. rob spriggs

    rob spriggs New Member

    Joined:
    Jan 26, 2008
    Messages:
    28
    Likes Received:
    0
    thats great thanks, but what if the mins is more thatn 60, ie 74 i know that the hour will go up to 1 but what will happen to the remaining 14 seconds?
  4. pabloppp

    pabloppp New Member

    Joined:
    Feb 21, 2008
    Messages:
    53
    Likes Received:
    0
    Well, try this:

    if (minutes => 60)
    {
    minutes -= 60
    hour += 1
    }

    like this when minutes are more than 60 we add an our and we add the minutes -60
    Ex:
    74 min=
    1 hour + (74-60) min
    = 1 hour + 14 min
  5. The Ax

    The Ax Banned

    Joined:
    Mar 11, 2008
    Messages:
    647
    Likes Received:
    22

    var date = new Date();
    hrs = date.getHour
    mins = date.getMinutes
    secs = date.getSeconds

    log (hrs+" : "+mins+" : "+secs)

    Thats how you get the time
    ------------------double post merged------------------

    var date = new Date();
    hrs = date.getHour
    mins = date.getMinutes
    secs = date.getSeconds

    log (hrs+" : "+mins+" : "+secs)

    Thats how you get the time
  6. pabloppp

    pabloppp New Member

    Joined:
    Feb 21, 2008
    Messages:
    53
    Likes Received:
    0
    I think that's not what he was asking about...
  7. PAEz

    PAEz New Member

    Joined:
    Jan 29, 2008
    Messages:
    201
    Likes Received:
    10
    Convert the times to milliseconds add the millisecond values together and then convert the result back.
    See if this helps....
    Code:
    function timeToMS(day,hour,min,sec,ms){
    return ms+(sec*1000)+(min*60000)+(hour*3600000)+(day*86400000)
    }
    function msToTime(ms){
    milliseconds = ms% 1000;
    seconds = Math.floor(ms/1000) % 60;
    minutes = Math.floor(ms/60000) % 60;
    hours = Math.floor(ms/3600000) % 24;
    days = Math.floor(ms/86400000);
    log(days+" "+hours+" "+minutes+" "+seconds+" "+milliseconds);
    }
    
    time1=timeToMS(0,18,59,50,0);
    time2=timeToMS(1,0,0,15,0);
    msToTime(time1+time2);
  8. rob spriggs

    rob spriggs New Member

    Joined:
    Jan 26, 2008
    Messages:
    28
    Likes Received:
    0
    ok, thanks for all you help so far,problem that i have now is that i cant work out how to input the times?

    the only way that i have worked it out so far is to put the hours in one text field and then the minutes into another.

    i have tried various different methods of getting the times to add up but everything just gives the same two times in the output box, not a total of the two times.

    also how to i get the formula that PAEz above has posted to read these values and add them together for me? thanks

    i have tried to post a sample of the code that i am using but these pcs that i am using wont allow anything to upload

    Please Register or Log in to view images

  9. kurtisboyd

    kurtisboyd Member

    Joined:
    Oct 20, 2007
    Messages:
    610
    Likes Received:
    7
    Device:
    iPhone 4 (Black)
    Keep going with it, also, there's an app like this in the app store, so if someone could look around in it, you could get an idea of what you have to do.

    I think it's called time calculator or something...
  10. rob spriggs

    rob spriggs New Member

    Joined:
    Jan 26, 2008
    Messages:
    28
    Likes Received:
    0
    well i finally got it sorted, thanks a lot PAEz, it was your code that i managed to work.

    cheers for the help

Share This Page