La copia del código es la siguiente:
// La misma función de formato de marca de tiempo que PHP
// @param {string} formato
// @param {int} TimeStamp.
// @return {string} Cadena de tiempo formateado
Funcion Fecha (Formato, Timestamp) {
var a, jsdate = ((timestamp)? nueva fecha (marca de tiempo*1000): nueva fecha ());
var pad = function (n, c) {
if ((n = n + "") .length <c) {
devolver una nueva matriz (++ c - n.length) .Join ("0")+n;
} demás {
regresar n;
}
};
var txt_weekdays = ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"];
var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
var txt_months = ["", "enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
var f = {
// Día
D: function () {
Pad, de retorno (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.getday ();
},
z: function () {
return (jsdate - nueva fecha (jsdate.getblyear () + "/1/1"))/864e5 >> 0;
},
// Semana
W: function () {
var a = fz (), b = 364 + fl () - a;
var nd2, nd = (nueva fecha (jsdate.getblyear () + "/1/1"). getday () || 7) - 1;
if (b <= 2 && ((jsdate.getday () || 7) - 1) <= 2 - b) {
regresar 1;
} demás{
if (a <= 2 && nd> = 4 && a> = (6 - nd)) {
nd2 = nueva fecha (jsdate.getblyaryar () - 1 + "/12/31");
fecha de retorno ("w", math.round (nd2.gettime ()/1000));
} demás{
return (1 + (nd <= 3? ((a + nd) / 7): (a - (7 - nd)) / 7) >> 0);
}
}
},
// Mes
F: function () {
return txt_months [fn ()];
},
m: function () {
almohadilla de retorno (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) {
devolver 28 + fl ();
} demás{
if (n & 1 && n <8 ||! (n & 1) && n> 7) {
regreso 31;
} demás{
regresar 30;
}
}
},
// Año
L: function () {
var y = fy ();
return (! (y & 3) && (y % 1e2 ||! (y % 4e2)))? 1: 0;
},
// O no es compatible todavía
Y: function () {
return jsdate.getblyar ();
},
y: function () {
return (jsdate.getblyar () + "") .slice (2);
},
// Tiempo
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 (thesegundos/86.4);
if (beat> 1000) beat -= 1000;
if (beat <0) beat += 1000;
if ((string (beat)). longitud == 1) beat = "00"+beat;
if ((string (beat)). longitud == 2) beat = "0"+beat;
Beat de regreso;
},
g: function () {
return jsdate.gethours () % 12 || 12;
},
G: function () {
return jsdate.gethours ();
},
H: function () {
almohadilla de retorno (fg (), 2);
},
H: function () {
Return Pad (jsdate.gethours (), 2);
},
i: function () {
Return Pad (jsdate.getminutes (), 2);
},
S: function () {
Return Pad (jsdate.getSeconds (), 2);
},
// aún no lo compatibles
// zona horaria
// no es compatible todavía
// todavía no apoyé
O: function () {
var t = pad (math.abs (jsdate.gettimezoneOffset ()/60*100), 4);
if (jsdate.gettimezoneOffset ()> 0) t = "-" + t; else t = " +" + t;
regresar t;
},
P: function () {
var o = fo ();
return (O.Substr (0, 3) + ":" + O.Substr (3, 2));
},
// T aún no es compatible
// Z aún no es compatible
// Fecha completa/hora
c: function () {
return fy () + "-" + fm () + "-" + fd () + "t" + fh () + ":" + fi () + ":" + fs () + fp ();
},
// r no es compatible todavía
U: function () {
return math.round (jsdate.gettime ()/1000);
}
};
return format.replace (/[//]? ([A-Za-Z])/G, Función (T, S) {
if (t! = s) {
// escapó
ret = s;
} else if (f [s]) {
// existe una función de fecha
ret = f [s] ();
} demás{
// nada especial
ret = s;
}
regreso de regreso;
});
}