Read the current time using script.

The below function is used to read the current time in 24 hours.

function timestamp() {
                    var str = "";

                    var currentTime = new Date();
                    var hours = currentTime.getHours();
                    var minutes = currentTime.getMinutes();
                    var seconds = currentTime.getSeconds();
                    str += hours + ":" + minutes + ":" + seconds + " ";
                    return str;
                }
                var currentTime = timestamp();


The below function is used to read the current time in 12 hours.

function timestamp() {
    var str = "";

    var currentTime = new Date();
    var hours = currentTime.getHours();
    log.debug("hours",hours);
    var minutes = currentTime.getMinutes();
    log.debug("minutes",minutes)
    var seconds = currentTime.getSeconds();
    log.debug("seconds",seconds);
    var meridian = "";
    if (hours > 12) {
        meridian += "pm";
    } else {
        meridian += "am";
    }
    if (hours > 12) {

        hours = hours - 12;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }
    str += hours + ":" + minutes + ":" + seconds + " ";

    return str+meridian;
}
var currentTime = timestamp();
log.debug("currentTime",currentTime);

Leave a comment

Your email address will not be published. Required fields are marked *