Javascript Date formatDay(pattern, dayNames = [], monthnames = [])

Description

Javascript Date formatDay(pattern, dayNames = [], monthnames = [])


Date.prototype.formatDay = function (pattern, dayNames = [], monthnames = []) {
    pattern = pattern.replace(/dddd/g, dayNames[this.getDay()]);
    pattern = pattern.replace(/dd/g, this.getDate().toString().padLeft(2, 0));
    pattern = pattern.replace(/mmm/g, monthnames[this.getMonth()]);
    pattern = pattern.replace(/mm/g, (this.getMonth() + 1).toString().padLeft(2, 0));
    pattern = pattern.replace(/yyyy/g, this.getFullYear().toString());
    pattern = pattern.replace(/yy/g, this.getFullYear().toString().substr(2, 2));
    return pattern;
};



PreviousNext

Related