1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| if (!Date.prototype.format){ Object.defineProperty(Date.prototype, "format", { value: Date.prototype.format = function (fmt) { var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; var weekShortName = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat']; var month = ["December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November"] var monthShortName = ["Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov"]; var regs = { '%y': this.getFullYear() % 100, '%Y': this.getFullYear(), '%m': this.getMonth() + 1, '%d': this.getDate(), '%H': this.getHours(), '%I': this.getHours() % 12 + 1, '%M': this.getMinutes(), '%S': this.getSeconds(), '%a': weekShortName[this.getDay()], '%A': week[this.getDay()], '%b': monthShortName[this.getMonth()], '%B': month[this.getMonth()], '%c': this.toLocaleString(), '%j': getDayNumber(), '%u': Math.ceil(getDayNumber() / 7), '%U': this.getDay() == 0 ? parseInt(getDayNumber() / 7) + 1 : parseInt(getDayNumber() / 7), '%w': this.getDay(), "%q": Math.ceil((this.getMonth() + 1) / 3), '%x': this.toLocaleDateString(), '%X': this.toLocaleTimeString(), };
for (var k in regs) { if (new RegExp("(" + k + ")").test(fmt)) { fmt = fmt.replace(RegExp.$1, regs[k]); } } return fmt; }, configurable: true, enumerable: false, writable: true }); }
|