Una cosa que molesta a los blogueros: no quiero escribir a mano, pero en el método final, sigo escribiendo a mano, lo grabo
Al escribir Js, hay un lugar donde se usa la fecha , y el requisito es el formato aaaa - MM - dd , por lo que se piensa en la función de formato
// Current time var Time = new Date (). Format ("aaaa-MM-dd"); Pero en ese momento el formato se reportó en rojo, y luego me enteré de que es necesario llamar a la función de tiempo cuando la página carga js , El código es el siguiente:
$ (function () { datatime (); });
// 时间 函数 function datatime () { Date.prototype.format = function (format) { var o = { "M +": this.getMonth () + 1, // mes "d +": this.getDate (), / / día "h +": this.getHours (), // hora "m +": this.getMinutes (), // minuto "s +": this.getSeconds (), // segundo "q +": Math.floor (( this.getMonth () + 3) / 3), // trimestre "S": this.getMilliseconds () // milisegundo } if (/ (y +) /. test (format)) { format = format.replace (RegExp. $ 1, (this.getFullYear () + ""). Substr (4 - RegExp. $ 1.length)); } para (var k en o) { if (new RegExp ("(" + k + ")"). prueba (formato)) { format = format.replace (RegExp. $ 1, RegExp. $ 1.length == 1? o [k]: ("00" + o [k]). substr (("" + o [k]). length)) ; } } formato de retorno; } }