Skip to main content
Fightergator
Inspiring
Nov 17, 2022 1:16 AM UTC
Answered

Any Suggestions on How to Get System In JavaScript

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 is closed to new replies. Start a new post to keep the conversation going.
    K.Daube
    K.DaubeCorrect answer
    Community Expert
    Nov 17, 2022 11:12 AM UTC
    timeNow = getTimeStamp();
    $.writeln(timeNow);

    4 replies

    K.Daube
    Community Expert
    K.DaubeCommunity ExpertCorrect answer
    Community Expert
    Nov 17, 2022 11:12 AM UTC
    timeNow = getTimeStamp();
    $.writeln(timeNow);
    Translate
    Fightergator
    Inspiring
    Nov 17, 2022 10:55 PM UTC

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

    Translate