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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
var dateformat = function () {var token =/d{1,4}|m{1,4}|yy (?: yy)? | ([HHMSTT]) 1?| [llosz]|] [^"]*"|' [^ ']* '/g, timezone =/b (?: [Pmcea][sdp]t| (?:P acific| mountain| central| eastern| Atlantic) (?: standard| Daylight| prevailing) time| (?: gmt| UTC) (?: [-+]d{4})? b/g, timezoneclip =/[^-+da-z]/g, pad = function (val, len) {val = String (val); len = Len | | 2; while (Val.length < le N) val = "0" + val; return Val; }; //regexes and supporting functions are cached through return function (date, closure, UTC) {var DF = mask Mat //Can ' t provide UTC if you skip other args (Use the "UTC: Mask prefix) if (arguments.length = 1 && O Bject.prototype.toString.call (date) = = "[Object String]" &&!/d/.test (date) {mask = date; date = undefined;} &n Bsp Passing date through date applies date.parse, if necessary date = date? New Date: new Date; if (isNaN (date)) throw SyntaxError ("Invalid Date"); Mask = String (Df.masks[mask] | | | mask | | df.masks["Default"]); //Allow setting the UTC argument via the Mask if (Mask.slice (0, 4) = = "UTC:") {mask = Mask.slice (4); UTC = True; } var _ = UTC? "GETUTC": "get", D = date[_ + "date"] (), d = date[_ + "Day" (), M = date[_ + "Month"] (), y = date[_ + "Fullyear"] (), H = Date[_ + "Hours"] (), M = date[_ + "Minutes"] (), s = date[_ + "Seconds"] (), L = Date[_ + "milliseconds"] (), o = UTC? 0:date.gettimezoneoffset (), flags = {D:D, dd:pad (d), ddd:df.i18n.daynames[d], Dddd:df.i18n.daynames[d + 7], m:m + 1, Mm:pad (M + 1), mmm:df.i18n.monthnames[m], mmmm:df.i18n.monthnames[m +), yy:string (y). Slice (2), yyyy:y, h:h% 1 2 | | Hh:pad (h%), H:h, Hh:pad (h), M:m, Mm:pad (M), S:s, Ss:pad (s), L:pad (L, 3), L:pad (L > 99? Math.Round (L/10): L), T:h < 12? "A": "P", tt:h < 12? "AM": "PM", t:h < 12? "A": "P", Tt:h < 12? "AM": "PM", Z:UTC? "UTC": (String (date). Match (timezone) | | [""]). POPs (). replace (Timezoneclip, ""), O: (o > 0?) -" : "+") + pad (math.abs (o)/(Math.floor) + math.abs (o)%, 4), S: ["th", "st", "nd", "rd"][d% > 3? 0: (d% 10 0-d%!=) * d% 10]}; Return Mask.replace (token, function ($) {return $ in flags flags[$0]: $0.slice (1, $0.length-1);}); }; }(); //Some common Format Strings dateformat.masks = {"Default": "DDD mmm dd yyyy HH:MM:ss", ShortDate: "M/d/yy", Medi Umdate: "Mmm D, yyyy", longdate: "Mmmm d, yyyy", fulldate: "dddd, mmmm d, yyyy", Shorttime: "h:mm TT", Mediumtime: "H:mm:s S TT ", longtime:" H:mm:ss tt Z ", Isodate:" Yyyy-mm-dd ", Isotime:" HH:MM:ss ", Isodatetime:" Yyyy-mm-dd ' T ' HH:MM:ss ", ISOUTCD Atetime: "Utc:yyyy-mm-dd ' T ' HH:MM:ss ' Z '"}; //Internationalization strings dateformat.i18n = {daynames: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "S Unday "," Monday "," Tuesday "," Wednesday "," Thursday "," Friday "," Saturday "], monthnames: [" A Few "," Feb "," Mar "," APR "," "M Ay "," June "," Aug "," Nov "," Sep "," Oct "," January "," Dec "," February "," March "," April "," may "," June "," July "," August "," September "," October "," November "," December "]}; /For convenience ... Date.prototype.format = function (mask, UTC) {return DateFormat (this, mask, UTC); |