Copy link to clipboard
Copied
I'm trying to get the processing start time and then subtract it from the processing end time. I need to convert the time before doing the math, right?
both of my scand commands give me NULL. Can you guys see what I did wrong here?
var startTime = util.printd("HH:MM:ss", new Date());
var compStartTime = util.scand("HH:MM:ss",startTime);
app.alert("start time converted: "+compStartTime);
// Do some stuff
var finishTime = util.printd("HH:MM:ss", new Date());
var compFinishTime = util.scand("HH:MM:ss", finishTime);
var calcTime = compFinishTime - compStartTime;
var finalTime = util.printd("HH:MM:ss",calcTime);
app.alert(finalTime);
Thanks for your help!
Rick
Hi,
I think it is a little complicated, as I don't think you need to worry about format until you are ready to show it to the user so you code could be simplified to
...function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = parseInt((duration / 1000) % 60),
minutes = parseInt((duration / (1000 * 60)) % 60),
hours = parseInt((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minu
Copy link to clipboard
Copied
rickr43378632 wrote
I need to convert the time before doing the math, right?
No. Consider the following
var t1 = new Date();
// Do stuff
var t2 = new Date();
// Show user the number of milliseconds between t2 and t1
app.alert(t2 - t1);
Copy link to clipboard
Copied
Hi,
I think it is a little complicated, as I don't think you need to worry about format until you are ready to show it to the user so you code could be simplified to
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = parseInt((duration / 1000) % 60),
minutes = parseInt((duration / (1000 * 60)) % 60),
hours = parseInt((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
var startTime = new Date();
// Do some stuff
var finishTime = new Date();
var finalTime = finishTime - startTime;
app.alert ( msToTime ( finalTime));
Hope this helps, and there a probably other ways.
Malcolm
Copy link to clipboard
Copied
Thanks Malcolm and George!