• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Converting time with scand is giving me NULL

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

362

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
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 12, 2018 Sep 12, 2018

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

...

Votes

Translate

Translate
LEGEND ,
Sep 12, 2018 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);

Votes

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
community guidelines
Community Expert ,
Sep 12, 2018 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

Votes

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
community guidelines
Community Beginner ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

LATEST

Thanks Malcolm and George!

Votes

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
community guidelines