Converting time with scand is giving me NULL

Community Beginner ,
Sep 12, 2018

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

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

98

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Converting time with scand is giving me NULL

Community Beginner ,
Sep 12, 2018

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

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

99

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 12, 2018 0
Adobe Community Professional ,
Sep 12, 2018

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);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 12, 2018 1
Adobe Community Professional ,
Sep 12, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 12, 2018 1
Community Beginner ,
Sep 12, 2018

Copy link to clipboard

Copied

Thanks Malcolm and George!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 12, 2018 0