String.prototype.PadLeft = function (nLen, sPad) { if (typeof sPad !== "string") sPad = " "; if (typeof nLen !== "number") nLen = 2; var sResult = this; while (sResult.length < nLen) sResult = sPad + sResult; return sResult; }; String.prototype.PadRight = function(sPad, nLen) { if (typeof sPad !== "string") sPad = " "; if (typeof nLen !== "number") nLen = 2; var sResult = this; while (sResult.length < nLen) sResult += sPad; return sResult; }; String.prototype.Trim = function () { return this.replace(/^\s+|\s+$/g, ""); }; String.prototype.TrimLeft = function () { return this.replace(/^\s+/, ""); }; String.prototype.TrimRight = function () { return this.replace(/\s+$/, ""); };
String.prototype javascript
Date.prototype javascript
Date.prototype.Format = function (sFormat) { if (typeof sFormat !== "string") return this.getFullYear().toString() + (this.getMonth() + 1).toString().PadLeft("0", 2) + this.getDate().toString().PadLeft("0", 2); var that = this; return sFormat.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?/g, function (sFormat) { switch (sFormat) { case "yyyy": return that.getFullYear().toString(); case "yy": return that.getFullYear().toString().substring(2, 4); case "MM": return (that.getMonth() + 1).toString().PadLeft(2, "0"); case "dd": return that.getDate().toString().PadLeft(2, "0"); case "hh": return (that.getHours() <= 12 ? that.getHours() : (that.getHours() - 12)).toString().PadLeft(2, "0"); case "HH": return that.getHours().toString().PadLeft(2, "0"); case "mm": return that.getMinutes().toString().PadLeft(2, "0"); case "ss": return that.getSeconds().toString().PadLeft(2, "0"); case "M": return (that.getMonth() + 1).toString(); case "d": return that.getDate().toString(); case "h": return (that.getHours() <= 12 ? that.getHours() : (that.getHours() - 12)).toString(); case "H": return that.getHours().toString(); case "m": return tht.getMinutes().toString(); case "s": return that.getSeconds().toString(); } }); };
Subscribe to:
Posts (Atom)