Skip to main content
Fightergator
Inspiring
November 17, 2022
Answered

Any Suggestions on How to Get System In JavaScript

  • November 17, 2022
  • 1 reply
  • 439 views

I'm working in the FrameMaker ExtendScript editor and want my script to log start and end times to the console in hours:minutes:seconds.  I've written the code below, which just keeps writing the same time over and over.  The timeNow variable only changes when the script is first started, and sometimes not even then.  When I run the script without the loop and without the function, it appears to run fine; giving me a new current time each time I run it.  Thoughts, suggestions...easier way to do this? 

//Test of a timeNow function for timing script
//start and end
var timeNow, strSeconds;
for (var i = 0; i < 6; i++){ //Function test loop
    for (var j = 0; j < 100000000; j++){  //Timer
        }
getTimeStamp();
$.writeln(timeNow);
}
function getTimeStamp() {
    var timeNow;
    var hours = (new Date()).getHours();
    var minutes = (new Date()).getMinutes();
    var seconds = (new Date()).getSeconds();
        if (seconds <= 9) {
        strSeconds = "0" + seconds.toString();
        timeNow = hours + ":" + minutes + ":" + strSeconds;
        } else {
        timeNow = hours + ":" + minutes + ":" + seconds;
    }
    return(timeNow);
}

 

    This topic has been closed for replies.
    Correct answer K.Daube
    timeNow = getTimeStamp();
    $.writeln(timeNow);

    1 reply

    K.Daube
    Community Expert
    K.DaubeCommunity ExpertCorrect answer
    Community Expert
    November 17, 2022
    timeNow = getTimeStamp();
    $.writeln(timeNow);
    Fightergator
    Inspiring
    November 17, 2022

    Many thanks for that.  I knew it had to be easier than what I was trying to do.  Have a great day.