Don't worry, I made a javascript only version for ya! Much simplerer!
Date.prototype.format = function (pattern, utc) {
var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
function ii(i, len) {
var s = i + "";
len = len || 2;
while (s.length < len) s = "0" + s;
return s;
}
var y = utc ? this.getUTCFullYear() : this.getFullYear();
pattern = pattern.replace(/(^|[^\\])yyyy+/g, "$1" + y);
pattern = pattern.replace(/(^|[^\\])yy/g, "$1" + y.toString().substr(2, 2));
pattern = pattern.replace(/(^|[^\\])y/g, "$1" + y);
var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
pattern = pattern.replace(/(^|[^\\])MMMM+/g, "$1" + MMMM[0]);
pattern = pattern.replace(/(^|[^\\])MMM/g, "$1" + MMM[0]);
pattern = pattern.replace(/(^|[^\\])MM/g, "$1" + ii(M));
pattern = pattern.replace(/(^|[^\\])M/g, "$1" + M);
var d = utc ? this.getUTCDate() : this.getDate();
pattern = pattern.replace(/(^|[^\\])dddd+/g, "$1" + dddd[0]);
pattern = pattern.replace(/(^|[^\\])ddd/g, "$1" + ddd[0]);
pattern = pattern.replace(/(^|[^\\])dd/g, "$1" + ii(d));
pattern = pattern.replace(/(^|[^\\])d/g, "$1" + d);
var H = utc ? this.getUTCHours() : this.getHours();
pattern = pattern.replace(/(^|[^\\])HH+/g, "$1" + ii(H));
pattern = pattern.replace(/(^|[^\\])H/g, "$1" + H);
var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
pattern = pattern.replace(/(^|[^\\])hh+/g, "$1" + ii(h));
pattern = pattern.replace(/(^|[^\\])h/g, "$1" + h);
var m = utc ? this.getUTCMinutes() : this.getMinutes();
pattern = pattern.replace(/(^|[^\\])mm+/g, "$1" + ii(m));
pattern = pattern.replace(/(^|[^\\])m/g, "$1" + m);
var s = utc ? this.getUTCSeconds() : this.getSeconds();
pattern = pattern.replace(/(^|[^\\])ss+/g, "$1" + ii(s));
pattern = pattern.replace(/(^|[^\\])s/g, "$1" + s);
var f = utc ? this.getUTCMilliseconds() : this.getMilliseconds();
pattern = pattern.replace(/(^|[^\\])fff+/g, "$1" + ii(f, 3));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])ff/g, "$1" + ii(f));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])f/g, "$1" + f);
var T = H < 12 ? "AM" : "PM";
pattern = pattern.replace(/(^|[^\\])TT+/g, "$1" + T);
pattern = pattern.replace(/(^|[^\\])T/g, "$1" + T.charAt(0));
var t = T.toLowerCase();
pattern = pattern.replace(/(^|[^\\])tt+/g, "$1" + t);
pattern = pattern.replace(/(^|[^\\])t/g, "$1" + t.charAt(0));
var tz = -this.getTimezoneOffset();
var K = utc || !tz ? "Z" : tz > 0 ? "+" : "-";
if (!utc) {
tz = Math.abs(tz);
var tzHrs = Math.floor(tz / 60);
var tzMin = tz % 60;
K += ii(tzHrs) + ":" + ii(tzMin);
}
pattern = pattern.replace(/(^|[^\\])K/g, "$1" + K);
var day = (utc ? this.getUTCDay() : this.getDay()) + 1;
pattern = pattern.replace(new RegExp(dddd[0], "g"), dddd[day]);
pattern = pattern.replace(new RegExp(ddd[0], "g"), ddd[day]);
pattern = pattern.replace(new RegExp(MMMM[0], "g"), MMMM[M]);
pattern = pattern.replace(new RegExp(MMM[0], "g"), MMM[M]);
pattern = pattern.replace(/\\(.)/g, "$1");
return pattern;
};
modified 31-Mar-17 16:11pm.
|