Permítanme presentar el conjunto de funciones para obtener tiempo por JS.
$ (function () {var myDate = new Date (); var t = mydate.tolocaleString (); $ ("#time"). text (t); $ ("#time"). load ("sin título-1.html");});Obtener el tiempo de JavaScript se realiza utilizando la función de fecha incorporada
var myDate = new Date (); mydate.getyear (); // Obtenga el año actual (2 dígitos) mydate.getblyear (); // Obtenga el año completo (4 dígitos, 1970-????) mydate.getmonth (); // Obtenga el mes actual (0-11, 0 representa enero) myDate.getDate (); // Obtenga el día actual (1-31) mydate.getday (); // Obtenga la semana actual X (0-6, 0 representa el domingo) mydate.gettime (); // Obtenga la hora actual (milisegundos a partir de 1970.1.1) mydate.gethours (); // Obtenga el número actual de horas (0-23) mydate.getminutes (); // Obtenga el número actual de minutos (0-59) mydate.getSeconds (); // Obtenga el número actual de segundos (0-59) mydate.getMilliseConds (); // Obtenga el número actual de milisegundos (0-999) mydate.tolocaledateString (); // Obtenga la fecha actual var myTime = myDate.TOLOCALETIMETRING (); // Obtenga la hora actual mydate.tolocaleString (); // Obtenga la hora actual mydate.tolocaleString (); // Obtenga la fecha y la hora
Lista de métodos de biblioteca de scripts de fecha y hora
Date.prototype.Esteapyear jueces de salto de años Fecha.prototype.Format Formato Formato Fecha.prototype.dataadd Fecha de cálculo Fecha.prototype.datediff Compare la fecha de diferencia de fecha. El número máximo de días del mes en que la fecha es la fecha.
// ----------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- HH/HH/H/H TIME // mm/m minutos // ss/ss/s/s Segundos // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------- 100) .ToString (): '0' + (this.getyear () % 100)); str = str.replace (/mm/,this.getmonth ()> 9? This.getmonth (). ToString (): '0' + + this.getMonth ()); str = str.replace (/m/g,this.getmonth ()); str = str.replace (/w | w | w/g, week [this.getday ()]); str = str.replace (/ddd|ddd/,this.getDate ()> 9? this.getdate (). tostring ():: ' +' + ' +' + this.getDate ()); str = str.replace (/d|d/g,this.getdate ()); str = str.replace (/hhhhhh/,this.gethours ()> 9? this.gethours (). toString (): '0' + this.gethours ()); str = str.replace (/h|h/g,this.gethours ()); str = str.replace (/mm/,this.getminutes ()> 9? this.getminutes (). toString (): '0' + this.getminutes ()); str = str.replace (/m/g,this.getminutes ()); str = str.replace (/sss|ss/,this.getSeconds ()> 9? this.getSeconds (). ToString (): '0' + + this.getSeconds ()); str = str.replace (/s|s/g,this.getSeconds ()); return str;} //+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- daysbetween (dateOnee, dataTwo) {var onemonth = dateOne.substring (5, dateOne.lastIndexof ('-')); var oneday = dateOne.substring (dateOne.length, dateOne.lastIndexOf ('-')+1); var Oneyear = dateOne.substring (0, dateOne.indexof ('-'-'); Datetwo.substring (5, Datetwo.lastIndexof ('-')); var twoday = dataTwo.substring (Datetwo.length, datetwo.lastIndexof ('-')+1); var twoyear = dataTwo.substring (0, dataTwo.indexof ('-')); cha = ((date.Parse (onemonth+'/'+oneday+'/'+oneYear)- date.Parse (twomonth+'/'+twoday+'/'+twoyear))/86400000); return Math.abs(cha);}//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Date calculation //+--------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------- Número)); caso 'd': retorno nueva fecha (date.Parse (dttmp) + (86400000 * número)); caso 'w': return new date (date.Parse (dttmp) + ((86400000 * 7) * número)); case 'q': return nueva fecha (dttmp.gettylyar (), (dttmp.getmonth (()) dttmp.getDate (), dttmp.gethours (), dttmp.getminutes (), dttmp.getSeConds ()); case 'm': return new Date (dttmp.getblyear (), (dttmp.getmonth () + number, dtttmp.getdate (), dttmp.gethourss (), (), + number, dtttmp.getdate (), dttmp.gethours (), (), + number, dtttmp.getdate (), dttmp.gethours (), (), + number, dtttmp.getdate (), dttmp.gethourss () dttmp.getminutes (), dttmp.getminutes (), dttmp.getSeconds ()); Case 'Y': return New Date ((dttmp.getblyear () + número), dttmp.getmonth (), dttmp.getdate (), dttmp.gethours (), dttmp.getminutes (),,,,) dttmp.getSeconds ());}} //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- parseInt((dtEnd - dtStart) / 1000);case 'n' :return parseInt((dtEnd - dtStart) / 60000);case 'h' :return parseInt((dtEnd - dtStart) / 3600000);case 'd' :return parseInt((dtEnd - dtStart) / 86400000);case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7));case 'm' :return parseInt((dtEnd - dtStart) / (86400000 * 7));case 'm' :return parseInt((dtEnd - dtStart) / (86400000 * 7));case 'm' :return parseInt((dtEnd - dtStart) / (86400000 * 7));case 'm' : return parseInt ((dtend - dtStart) / (86400000 * 7)); caso 'm': return parseInt ((dtend - dtStart) / (86400000 * 7)); case 'm': return (dtend.getmonth ()+1)+((dtend.getyTyLyear () - dtstart.getfulfyear () *) - 12) (dtstart.getMonth ()+1); caso 'y': return dtend.getblyear () - - dtstart.getblyaryar ();}} //+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- esto; var str = myDate.tolocaledateString (); if (showweek) {var week = ['day', 'one', 'dos', 'tres', 'cuatro', 'cinco', 'Six']; str + = 'Week' + Week [myDate.getday ()];} return str;}//+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sdate = datestr.replace (/(^/s+|/s+$)/g, ''); // Retire los espacios en ambos lados; if (sdate == '') return true; // Si el formato satisface a yyy-(/) mm-(/) dd o a yyyy-(/) m-(/) dd o yyyy-(/) m-(/) d o yyyy-(/) mm-(/) d, se reemplazará con '' // en la dat. Yyyy-mm/dd (2003-3/21), y la base de datos se convertirá automáticamente a yyyyy-mm-dd var s = sdate.replace (/[/d] {4,4} [/-/] {1} [/d] {1,2} [/-/] {1} [/d] {1} [/d] 1} [/d] {1} [/d] {1} [/d] {1} [/d] {1} [/d] {1} [/d] {1} [/d] {1} [/d] Satisface a yyyy-mm-dd o yyyyy-m-dd o yyyy-md o yyyy-mm-d {var t = new date (sdate.replace (//-/g, '/')); var ar = sdate.split (/[-/:]/); if (ar [0]! = t.getyear () || ar [1] ar [2]! = t.getDate ()) {// Alert ('Formato de fecha incorrecta! El formato es: aaa yyyy-mm-dd o aaaayyy/mm/dd. Presta atención a los años bisiestos'); return false;}} else {// alerta ('Formato de fecha incorrecta! El formato es: aaa yyyy-mm-dd o aaayyy/mm/dd. Presta atención a los años salas.'); return false;} return; verdadero;} //+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- }): (/d {1,2}) $/; var r = str.match (reg); if (r == null) return false; r [2] = r [2] -1; var d = new date (r [1], r [2], r [3], r [4], r [5], r [6]); if (d.getgleflefle ()! = R [1]) de regreso falso; if (d.getMonth ()! = r [2]) return false; if (d.getDate ()! = r [3]) return false; if (d.gethours ()! = r [4]) return FALSE; if (D.getMinutes ()! = R [5]) return false false; if (d.getSeconds ()! = R [6]) return false; return; return; return; return; verdadero;} //+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------- myDate.getDate (); myArray [3] = myDate.getHours (); myArray [4] = myDate.getminutes (); myArray [5] = myDate.getSeconds (); return MyArray;} //+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------- partstr = '' '; var Week = [' Day ',' One ',' Two ',' Three ',' Four ',' Five ',' Six ']; Switch (Interval) {Case' y ': PartStr = MyDate.GetTlyLeear (); Break; Case' m ': PartStr = myDate.getMonth ()+1; break; case' d 'd': partstr = myDate.getDate (); break; case; Semana [myDate.getDay ()]; break; case 'ww': partstr = myDate.weeknuMoFyear (); break; case 'h': partstr = myDate.gethours (); break; case 'n': partstr = myDate.getminutes (); break; break; case 's': partstr = myDate.getSeconds (); break;} break;} break;} devuelve partstr;} //+------------------------------------------------------------------------------------------------------------------------------- (nueva fecha (ary [0], ary [1] +1,1)); var date2 = date1.dateadd (1, 'm', 1); var result = datediff (date1.format ('yyyy-mm-dd'), date2.format ('yyyyy-mm-dd'); regreso resultado;} //+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- myDate.ToArray (); var año = ary [0]; var mes = ary [1] +1; var day = ary [2]; document.write ('<script language = vBscript /> /n') ;Document.Write('myDate = dateValue (' '+mes+'-'+día+'-'+año+' '') /n'); document.WRESTRES DatePart ('ww', mydate) /n '); document.write (' /n '); return result;}//+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Convert string to date type //| Formato mm/dd/aaa yyy mm-dd-yyyy yyyy/mm/dd Yyyy-mm-dd //+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------- Fecha (arys [0],-ary [1], arys [2]);} return mydate;}