A cópia do código é a seguinte:
// a mesma função de formatação de timestamp que PHP
// @param {String} formato
// @param {int} timestamp a hora de formatar os padrões para o horário atual
// @return {string} string de tempo formatada
Data da função (formato, registro de data e hora) {
var a, jsdate = ((timestamp)? New Date (Timestamp*1000): new Date ());
var pad = função (n, c) {
if ((n = n + "") .Length <c) {
Retornar nova matriz (++ c - n.Length) .Join ("0")+n;
} outro {
retornar n;
}
};
var txt_weekdays = ["domingo", "segunda -feira", "terça -feira", "quarta -feira", "quinta -feira", "sexta -feira", "sábado"];
var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
var txt_months = ["", "janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"];
var f = {
// Dia
D: function () {
almofada de retorno (fj (), 2);
},
D: function () {
t = fl (); retornar t.substr (0,3);
},
j: function () {
return jsdate.getdate ();
},
L: function () {
retornar txt_weekdays [fw ()];
},
N: function () {
retornar fw () + 1;
},
S: function () {
retornar txt_ordin [fj ()]? txt_ordin [fj ()]: 'th';
},
W: function () {
return jsdate.getday ();
},
z: function () {
Return (jsdate - New Date (jsdate.getlyear () + "/1/1"))/864e5 >> 0;
},
// Semana
W: function () {
var a = fz (), b = 364 + fl () - a;
var nd2, nd = (nova data (jsdate.getlyear () + "/1/1"). getDay () || 7) - 1;
if (b <= 2 && ((jsdate.getday () || 7) - 1) <= 2 - b) {
retornar 1;
} outro{
if (a <= 2 && nd> = 4 && a> = (6 - nd)) {
nd2 = nova data (jsdate.getlyear () - 1 + "/12/31");
Data de retorno ("W", Math.Round (nd2.gettime ()/1000));
} outro{
retornar (1 + (nd <= 3? ((A + nd) / 7): (a - (7 - nd)) / 7) >> 0);
}
}
},
// Mês
F: function () {
retornar txt_months [fn ()];
},
M: function () {
almofada de retorno (fn (), 2);
},
M: function () {
t = ff (); retornar t.substr (0,3);
},
n: function () {
return jsdate.getmonth () + 1;
},
t: function () {
var n;
if ((n = jsdate.getmonth () + 1) == 2) {
retornar 28 + fl ();
} outro{
if (n & 1 && n <8 ||! (n & 1) && n> 7) {
retornar 31;
} outro{
retornar 30;
}
}
},
// Ano
L: function () {
var y = fy ();
retornar (! (y & 3) && (y % 1e2 ||! (y % 4e2))? 1: 0;
},
// não ainda não suportado
Y: function () {
return jsdate.getlyear ();
},
y: function () {
return (jsdate.getlyear () + "") .slice (2);
},
// Tempo
a: function () {
retornar jsdate.gethours ()> 11? "PM": "Am";
},
A: function () {
retornar fa (). touppercase ();
},
B: function () {
// Peter Paul Koch:
var off = (jsdate.getTimeZoneOffSet () + 60)*60;
var theSegunds = (jsdate.gethours () * 3600) +
(jsdate.getminutes () * 60) +
jsdate.getSeconds () + OFF;
var beat = Math.Floor (TheSegunds/86.4);
if (batida> 1000) batida -= 1000;
if (bate <0) batida += 1000;
if (((string (beat)). comprimento == 1) beat = "00"+beat;
if (((string (beat)). comprimento == 2) beat = "0"+beat;
batida de retorno;
},
G: function () {
retornar jsdate.gethours () % 12 || 12;
},
G: function () {
return jsdate.gethours ();
},
h: function () {
almofada de retorno (FG (), 2);
},
H: function () {
Pad Pad (jsdate.gethours (), 2);
},
i: function () {
Pad Pad (jsdate.getminutes (), 2);
},
s: function () {
Pad Pad (jsdate.getSeconds (), 2);
},
// você ainda não foi suportado
// fuso horário
// e ainda não suportado
// eu ainda não apoiei
O: function () {
var t = pad (math.abs (jsdate.getTimeZoneoffSet ()/60*100), 4);
if (jsdate.getTimeZoneOffSet ()> 0) t = "-" + t; else t = " +" + t;
retornar t;
},
P: function () {
var o = fo ();
retornar (O.substr (0, 3) + ":" + O.substr (3, 2));
},
// ainda não foi suportado
// z ainda não suportado
// data completa/hora
C: function () {
retornar fy () + "-" + fm () + "-" + fd () + "t" + fh () + ":" + fi () + ":" + fs () + fp ();
},
// ainda não foi suportado
U: function () {
return math.round (jsdate.gettime ()/1000);
}
};
retornar format.replace (///]? ([a-za-z])/g, função (t, s) {
if (t! = s) {
// escapou
ret = s;
} else if (f [s]) {
// existe uma função de data
ret = f [s] ();
} outro{
// Nada de especial
ret = s;
}
retornar retorno;
});
}