## Converting time with scand is giving me NULL

Community Beginner ,
Sep 12, 2018

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

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

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 : minutes;  seconds = (seconds < 10) ? "0" + seconds : seconds;  return hours + ":" + minutes + ":" + seconds + "." + milliseconds;}var startTime = new Date();// Do some stuffvar 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

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

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

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

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 : minutes;  seconds = (seconds < 10) ? "0" + seconds : seconds;  return hours + ":" + minutes + ":" + seconds + "." + milliseconds;}var startTime = new Date();// Do some stuffvar 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

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
3 Replies 3
Sep 12, 2018

Copied

 rickr43378632  wroteI 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

Likes

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 1
Sep 12, 2018

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 stuffvar finishTime = new Date();var finalTime = finishTime - startTime;app.alert ( msToTime ( finalTime));`

Hope this helps, and there a probably other ways.

Malcolm

Likes

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 1
LATEST
Community Beginner ,
Sep 12, 2018