Javascript Date logFormat()

Description

Javascript Date logFormat()



Date.prototype.logFormat = function() {
    var h=this.getHours(), m = this.getMinutes(), s = this.getSeconds()
        mn = this.getMonth()+1, d = this.getDate(), y = this.getFullYear(), ampm = "AM";
    /*from   w ww.j  ava  2  s.c o  m*/
    m =  (m>10) ? m : "0"+m;
    d =  (d > 10) ? d : "0"+d;
    s =  (s > 10) ? s : "0" + s;
    mn = (mn > 10) ? mn : "0"+mn;
    ampm = (h>=12) ? "PM" : "AM";
    h = (h>12) ? h-12 : h;
    h=(h>10) ? h : "0"+h;
    
    return (d + "/" + mn + "/" + y + " " + h + ":" + m + ":" + s + ampm);
}

Javascript Date logFormat()

"use strict";/*  ww w. j  av a2  s .  c  om*/

Date.prototype.logFormat = function () {
    return this.getFullYear() + "-" + this.getMonth() + "-" + this.getDate() + ":" + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds() + "." + this.getMilliseconds();
};



PreviousNext

Related