La copie de code est la suivante:
// la même fonction de formatage horodatage que PHP
// @param {String} Format
// @param {int} horodatage du temps pour formater les défauts de l'heure actuelle
// @return {String} chaîne de temps formatée
Date de fonction (format, horodatage) {
var a, jsdate = ((horodat)? Nouvelle date (horodat * 1000): new Date ());
var pad = fonction (n, c) {
if ((n = n + "") .length <c) {
return nouveau tableau (++ c - n.length) .join ("0") + n;
} autre {
retour n;
}
};
var txt_weekdays = ["Sunday", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
var txt_months = ["", "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
var f = {
// Jour
d: function () {
RETOUR PAD (FJ (), 2);
},
D: function () {
t = fl (); retour t.substr (0,3);
},
j: function () {
return jsdate.getDate ();
},
l: function () {
return txt_weekdays [fw ()];
},
N: function () {
retour fw () + 1;
},
S: function () {
return txt_ordin [fj ()]? txt_ordin [fj ()]: 'th';
},
w: function () {
return jsdate.getDay ();
},
z: function () {
return (jsdate - new Date (jsdate.getlyear () + "/ 1/1")) / 864e5 >> 0;
},
// Semaine
W: function () {
var a = fz (), b = 364 + fl () - a;
var nd2, nd = (new Date (jsdate.getlyar () + "/ 1/1"). getday () || 7) - 1;
if (b <= 2 && ((jsdate.getday () || 7) - 1) <= 2 - b) {
retour 1;
} autre{
if (a <= 2 && nd> = 4 && a> = (6 - nd)) {
nd2 = new Date (jsdate.getlyar () - 1 + "/ 12/31");
Date de retour ("W", math.round (nd2.getTime () / 1000));
} autre{
return (1 + (nd <= 3? ((a + nd) / 7): (a - (7 - nd)) / 7) >> 0);
}
}
},
// Mois
F: function () {
return txt_months [fn ()];
},
m: function () {
RETOUR PAD (FN (), 2);
},
M: function () {
t = ff (); retour t.substr (0,3);
},
n: function () {
return jsdate.getMonth () + 1;
},
t: function () {
var n;
if ((n = jsdate.getMonth () + 1) == 2) {
retour 28 + fl ();
} autre{
if (n & 1 && n <8 ||! (n & 1) && n> 7) {
retour 31;
} autre{
retour 30;
}
}
},
// Année
L: function () {
var y = fy ();
return (! (y & 3) && (y% 1e2 ||! (y% 4e2)))? 1: 0;
},
// o pas encore pris en charge
Y: function () {
return jsdate.getlyear ();
},
y: function () {
return (jsdate.getlyar () + "") .slice (2);
},
// Temps
a: function () {
return jsdate.gethours ()> 11? "PM": "suis";
},
A: function () {
return fa (). ToupperCase ();
},
B: function () {
// Peter Paul Koch:
var off = (jsdate.getTimeZoneOffset () + 60) * 60;
var thesecondes = (jsdate.gethours () * 3600) +
(jsdate.getMinutes () * 60) +
jsdate.getSeconds () + off;
var beat = math.floor (ces secondes / 86.4);
if (beat> 1000) beat - = 1000;
if (beat <0) beat + = 1000;
if ((String (beat)). length == 1) beat = "00" + beat;
if ((String (beat)). Longueur == 2) beat = "0" + beat;
retour rythme;
},
g: function () {
retour jsdate.gethours ()% 12 || 12
},
G: function () {
return jsdate.gethours ();
},
h: function () {
RETOUR PAD (FG (), 2);
},
H: function () {
RETOUR PAD (JSDATE.GETHOURS (), 2);
},
i: function () {
return pad (jsdate.getMinutes (), 2);
},
s: function () {
return pad (jsdate.getSeconds (), 2);
},
// tu n'as pas encore pris en charge
// fuseau horaire
// E n'est pas encore pris en charge
// je n'ai pas encore pris en charge
O: function () {
var t = pad (math.abs (jsdate.getTimeZoneOffset () / 60 * 100), 4);
if (jsdate.getTimeZoneOffset ()> 0) t = "-" + t; else t = "+" + t;
retour t;
},
P: fonction () {
var o = fo ();
return (o.substr (0, 3) + ":" + o.substr (3, 2));
},
// t pas encore pris en charge
// z n'est pas encore pris en charge
// Date / heure complète
c: function () {
return fy () + "-" + fm () + "-" + fd () + "t" + fh () + ":" + fi () + ":" + fs () + fp ();
},
// R pas encore pris en charge
U: function () {
return math.round (jsdate.getTime () / 1000);
}
};
return format.replace (/ [//]? ([a-za-z]) / g, fonction (t, s) {
if (t! = s) {
// s'est échappé
ret = s;
} else if (f [s]) {
// Une fonction de date existe
ret = f [s] ();
} autre{
// rien de spécial
ret = s;
}
retour retour;
});
}