Search Results

Search found 1 results on 1 pages for 'user3709033'.

Page 1/1 | 1 

  • Trying to make a reusable function and display the result in a div

    - by user3709033
    I have this function that I am trying to work with. All I am trying to do is to get the values of days, hours, min and sec into the .overTime div. I want to use the same function over and over again because i have more divs in which I want to display the same values but in a diff manner. You guys are awesome Thank You. NowTime = new Date(); //Time Now StartTime = new Date($('#StartTime').val()); StopTime = new Date($('#StopTime').val()); function fixIntegers(integer){ if (integer < 0) integer = 0; if (integer < 10) return '0' + integer; return '' + integer; } function Test( difference ) { var toReturn = { days: 0, hours: 0, minutes: 0, seconds: 0 }; toReturn.seconds = fixIntegers(difference % 60); difference = Math.floor(difference / 60); toReturn.minutes = fixIntegers(difference % 60); difference = Math.floor(difference / 60); toReturn.hours = fixIntegers(difference % 24); difference = Math.floor(difference / 24); toReturn.days = fixIntegers(difference); return toReturn; } function run() { var output = Test( Math.floor( ( NowTime - StopTime ) / 1000 ) ); $('.OverTime').html( output.days + ':' + output.hours + ':' + output.minutes + ':' + seconds); } setInterval(run, 1000) FIDDLE: http://jsfiddle.net/8943U/47/

    Read the article

1