Javascript Date formatTime(pattern)

Description

Javascript Date formatTime(pattern)

Date.prototype.formatTime = function (pattern) {
    pattern = pattern.replace(/hh/g, this.getHours().toString().padLeft(2, 0));
    pattern = pattern.replace(/mm/g, this.getMinutes().toString().padLeft(2, 0));
    return pattern;
};

Javascript Date formatTime(pattern)

Date.prototype.formatTime = function (pattern) {
    pattern = pattern.replace(/hh/g, this.getHours().toString().padLeft(2, 0));
    pattern = pattern.replace(/mm/g, this.getMinutes().toString().padLeft(2, 0));
    pattern = pattern.replace(/ss/g, this.getSeconds().toString().padLeft(2, 0));
    return pattern;
};



PreviousNext

Related