Die Codekopie lautet wie folgt:
// die gleiche Zeitstempelformatierungsfunktion wie PHP
// @param {String} Format
// @param {int} Zeitstempel die Zeit zum Formatieren von Standards für die aktuelle Zeit
// @return {String} Formatierte Zeitzeichenfolge
Funktionsdatum (Format, Zeitstempel) {
var a, jsdate = ((Zeitstempel)? Neues Datum (Zeitstempel*1000): neues Datum ());
var pad = function (n, c) {
if ((n = n + "") .Length <c) {
Neuarray zurückgeben (++ C - n.length) .Join ("0")+n;
} anders {
return n;
}
};
var txt_Weekdays = ["Sunday", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
var txt_months = ["", "Januar", "Februar", "März", "April", "May", "June", "Juli", "Juli", "August", "September", "Oktober", "November", "Dezember"];
var f = {
// Tag
d: function () {
Return Pad (FJ (), 2);
},
D: function () {
t = fl (); return t.substr (0,3);
},
J: function () {
return jsdate.getDate ();
},
L: function () {
return txt_weekdays [fw ()];
},
N: function () {
Return fw () + 1;
},
S: function () {
return txt_ordin [fj ()]? txt_ordin [fj ()]: 'th';
},
W: function () {
return jsdate.getay ();
},
z: function () {
return (jsdate - neues Datum (jsdate.getingfullyear () + "/1/1"))/864e5 >> 0;
},
// Woche
W: function () {
var a = fz (), b = 364 + fl () - a;
var nd2, nd = (neues Datum (jsdate.getingfullyear () + "/1/1"). Getday () || 7) - 1;
if (b <= 2 && ((jsdate.getday () || 7) - 1) <= 2 - b) {
Rückkehr 1;
} anders{
if (a <= 2 && nd> = 4 && a> = (6 - nd)) {
nd2 = neues Datum (jsdate.getingfullyear () - 1 + "/12/11");
Rückgabedatum ("w", math.round (nd2.getTime ()/1000));
} anders{
return (1 + (nd <= 3? ((a + nd) / 7): (a - (7 - nd)) / 7) >> 0);
}
}
},
// Monat
F: function () {
return txt_months [fn ()];
},
M: function () {
Return Pad (fn (), 2);
},
M: function () {
t = ff (); return t.substr (0,3);
},
n: function () {
return jsdate.getMonth () + 1;
},
t: function () {
var n;
if ((n = jsdate.getMonth () + 1) == 2) {
Rückgabe 28 + fl ();
} anders{
if (n & 1 && n <8 ||! (N & 1) && n> 7) {
Rückkehr 31;
} anders{
Rückkehr 30;
}
}
},
// Jahr
L: function () {
var y = fy ();
return (! (y & 3) && (y % 1e2 ||! (y % 4e2)))? 1: 0;
},
// o Noch nicht unterstützt
Y: function () {
return jsdate.getingfullyear ();
},
y: function () {
return (jsdate.getingfullyear () + "") .slice (2);
},
// Zeit
A: function () {
return jsdate.gethours ()> 11? "PM": "Am";
},
A: function () {
return fa (). touppercase ();
},
B: function () {
// Peter Paul Koch:
var off = (jsdate.getTimezoneOffset () + 60)*60;
var theseconds = (jsdate.gethours () * 3600) +
(jsdate.getminutes () * 60) +
jsdate.getSeconds () + off;
var Beat = math.floor (die Kunden/86,4);
if (Beat> 1000) Beat -= 1000;
if (Beat <0) Beat += 1000;
if ((String (Beat)). Länge == 1) Beat = "00"+Beat;
if ((String (Beat)). Länge == 2) Beat = "0"+Beat;
Rückschlag;
},
g: function () {
return jsdate.gethours () % 12 || 12;
},
G: function () {
return jsdate.gethours ();
},
H: function () {
Return Pad (fg (), 2);
},
H: function () {
return pad (jsdate.gethours (), 2);
},
i: function () {
return pad (jsdate.getminutes (), 2);
},
S: function () {
return pad (jsdate.getSeconds (), 2);
},
// Du bist noch nicht unterstützt
// Zeitzone
// e noch nicht unterstützt
// Ich habe noch nicht unterstützt
O: function () {
var t = pad (math.abs (jsdate.getTimezoneOffset ()/60*100), 4);
if (jsdate.getTimeZoneOffset ()> 0) t = "-" + t; sonst t = " +" + t;
return t;
},
P: function () {
var o = fo ();
return (O.Substr (0, 3) + ":" + o.Substr (3, 2));
},
// T noch nicht unterstützt
// z noch nicht unterstützt
// Volles Datum/Uhrzeit
C: function () {
return fy () + "-" + fm () + "-" + fd () + "t" + fh () + ":" + fi () + ":" + fs () + fp ();
},
// r noch nicht unterstützt
U: function () {
return math.round (jsdate.getTime ()/1000);
}
};
return format.replace (/[//]? ([a-za-z])/g, Funktion (t, s) {
if (t! = s) {
// entkommen
ret = s;
} else if (f [s]) {
// Es gibt eine Datumsfunktion
ret = f [s] ();
} anders{
// nichts Besonderes
ret = s;
}
Rückkehr;
});
}