Stop watch with ouput (online, standalone or excel)

Associate
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
I am looking for a resource that will display a stop watch (in 10ths of seconds) and allow me to export a range of intervals to csv or excel

Basically I want to mimic trying to stop a clock dead on one second while showing the live clock in 10th of second intervals and then export the whole result set.

I have tried building it in excel but can only get down to full seconds on the live display using application.ontime to refresh a cell contents with the current time every second

Thanks
 
Soldato
Joined
18 Oct 2002
Posts
15,412
Location
The land of milk & beans
Excel sounds like the last thing you would want to build this in. Here's the result of boredom + my morning caffeine shot, using JS/jQuery: http://jsfiddle.net/RoryMcCrossan/9m5Qa/4/

Code:
var timer, startDate;

var updateDisplay = function() {
    var currentDate = new Date(),
        diff = formatTime(currentDate - startDate);    
    $('#timer-display').text(diff.timeString);
};

var stopTimer = function() {
    clearInterval(timer);
    $('#toggle-timer').text('Restart').data('running', false);
};

var pad = function(value, width) {
    value = value + '';
    return value.length >= width ? value : new Array(width - value.length + 1).join('0') + value;
}

var formatTime = function(ms) {
    var displayMinutes = pad(Math.floor(ms / (1000 * 60)), 2),
        displaySeconds = pad(Math.floor(ms / 1000) % 60, 2),
        displayMiliseconds = pad(Math.floor(ms % 1000), 3);
    
    return { 
        timeString: displayMinutes + ':' + displaySeconds + ':' + displayMiliseconds,
        bangOn: ms % 1000 > 975 || ms % 1000 < 25 // +-25ms each way tolerance
    }
}

function createTimer() {
    startDate = new Date();
    timer = setInterval(updateDisplay, 57); // odd interval to make the ms value seem faster
    $('#toggle-timer').text('Stop').data('running', true);
    $('#time-list').empty();
};

$('#toggle-timer').click(function() {
    $(this).data('running') ? stopTimer() : createTimer();
});

$('#get-time').click(function(e) {
    e.preventDefault();
    var currentDate = new Date(),
        diff = formatTime(currentDate - startDate),
        pClass = (diff.bangOn) ? 'bang-on' : '';
    $('#time-list').prepend($('<p />', { 
        "text": diff.timeString,  
        "class": pClass
    }));
});

createTimer();
Hopefully it should be of some help, if only at least to translate to whatever environment you want to use.

*edit*
Updated to add the check for clicking the button bang on a second (with a +-25ms tolerance) and changing the class to highlight it.
 
Last edited:
Associate
OP
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
Thanks for the code. Outside of VBA and very basic html I am clueless so I may have difficulty translating.

How would the above be modified to store say 30 results and export or display as a list?
 
Back
Top Bottom