Javascript Date timeNow()

Description

Javascript Date timeNow()


Date.prototype.timeNow = function(){
    return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
};

Javascript Date timeNow()

Date.prototype.timeNow = function () {
     return (this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes());
}

var newDate = new Date();
console.log(newDate.timeNow());/*from  w w  w  .j a  va  2  s  .  c  om*/

Javascript Date timeNow()

Date.prototype.timeNow = function()
{
 let retStr = "";
 retStr += ((this.getHours() < 10)?"0":"") + this.getHours();
 retStr += ":" + ((this.getMinutes() < 10)?"0":"") + this.getMinutes();
 return retStr;//  www . j av a  2  s  . c  o  m
}

Javascript Date timeNow()

// GLOBALS//from w  w  w  . j a  va  2 s .c  om

//Format time as 03:14:15
Date.prototype.timeNow = function () {
    return ((this.getHours() < 10)?"0":"") + ((this.getHours()>12)?(this.getHours()-12):this.getHours()) + ":" +
    ((this.getMinutes() < 10)?"0":"") + this.getMinutes() + ":" + ((this.getSeconds() < 10)?"0":"") +
    this.getSeconds() + ((this.getHours()>12)?(' PM'):' AM');
};

Javascript Date timeNow()

Date.prototype.timeNow = function () {
    return (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' +
           (this.getMinutes() < 10 ? '0' : '') + this.getMinutes() + ':' +
           (this.getSeconds() < 10 ? '0' : '') + this.getSeconds()
}



PreviousNext

Related