Permettez-moi d'introduire l'ensemble des fonctions pour obtenir du temps par JS.
$ (function () {var mydate = new Date (); var t = mydate.tolocalestring (); $ ("# time"). text (t); $ ("# time"). Load ("Untitled-1.html");});Obtenir le temps JavaScript est effectué en utilisant la fonction de date intégrée
var mydate = new Date (); myDate.getyEar (); // Obtenez l'année en cours (2 chiffres) MyDate.getlyar (); // Obtenez l'année complète (4 chiffres, 1970 - ????) MyDate.getMonth (); // Obtenez le mois en cours (0-11, 0 représente janvier) mydate.getDate (); // Obtenez le jour en cours (1-31) MyDate.getDay (); // Obtenez la semaine en cours X (0-6, 0 représente le dimanche) MyDate.getTime (); // Obtenez l'heure actuelle (millisecondes à partir de 1970.1.1) MyDate.Gethours (); // Obtenez le nombre actuel d'heures (0-23) MyDate.GetMinutes (); // obtient le nombre actuel de minutes (0-59) MyDate.getSeconds (); // obtient le nombre actuel de secondes (0-59) mydate.getMilliseconds (); // Obtenez le nombre actuel de millisecondes (0-999) MyDate.TolocaleDateString (); // Obtenez la date actuelle var mytime = mydate.tolocaletimestring (); // Obtenez l'heure actuelle mydate.tolocalestring (); // Obtenez l'heure actuelle mydate.tolocalestring (); // Obtenez la date et l'heure
Date and Heure Script Library Method List
Date.prototype.isapyear juges saut les années date.prototype.format date formatting date.prototype.dateadd date calcul Date.prototype.datediff compare date divergence date.prototype.tostring date.prototype.toarray date divisé en date. Prend le nombre maximum de jours du mois où la date est date.prototype.weeknumofyear juges la semaine de l'année où la date est une chaîne de stringtodate à ce jour isvalidDate Vérifiez la validité de la date de chèque
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- HH / HH / H / H TIME // MM / M MINUTES // SS / SS / S / S Seconds // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 / g, semaine [this.getday ()]); str = str.replace (/ddddd/,this.getDate ()> 9? this.getDate (). this.getDate ()); str = str.replace (/d|d/g,this.getDate ()); str = str.replace (/hhdanshh/,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 (dateOne, datetwo) {var onemMtH = dateOne.substring (5, dateOne.lastIndexof ('-')); var oneday = dateOne.substring (dateOne.length, dateOne.Lastidexof ('-') + 1); var oneyear = dateOne.substring (0, dateOn Datestwo.SubString (5, Datetwo.LastIndexof ('-')); var twoday = Datetwo.SubString (Datetwo.length, Datetwo.LastIndexof ('-') + 1); var Twoyear = Datetwo.SubString (0, Datetwo.indexof ('-'); cha = ((date.parse (Onemonth + '/' + OneDay + '/' + Oneyear) - Date.Parse (TwoMonth + '/' + Twoday + '/' + Twoyear)) / 86400000); Math.abs (cha);} // + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Number)); Case 'D': RETOUR NOUVELLE DATE (DATE.PARSE (DTTMP) + (86400000 * NUMÉRO)); CASE 'W': RETOUR NOUVELLE DATE (DATE.PARSE (DTTMP) + ((86400000 * 7) * dttmp.getDate (), dttmp.Gethours (), dttmp.getMinutes (), dttmp.getSeconds ()); case 'm': return new Date (dttmp.getlyear (), (dttmp.getmonth () + nombre, dttmp.getDate (), dttMp. dttmp.getMinutes (), dttmp.getMinutes (), dttmp.getSeconds ()); case 'y': return new Date ((dttmp.getlyear () + numéro), dttmp.getMonth (), dttmp.getDate (), dttmp.Gethours (), dttmp.getMinutes (), dtTmp.getSeconds());}}//+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- parseInt ((dtend - dtStart) / 1000); cas 'n': return parseInt ((dtend - dtstart) / 60000); case 'h': return parseInt ((dtend - dtstart) / 3600000); case 'd' dtstart) / (86400000 * 7)); cas 'm': retour parseInt ((dtend - dtStart) / (86400000 * 7)); case 'm': return parseInt ((dtend - dtstart) / (86400000 * 7)); case 'm': return parseint (dtend - dtstart) / (86400000 *); Cas; (dtenten : return parseInt ((dtend - dtstart) / (86400000 * 7)); case 'm': return parseInt ((dtend - dtStart) / (86400000 * 7)); case 'm': return (dtend.getMonth () + 1) + ((dtend.getlyar () - DTStart.getmuly ()) (dtstart.getMonth () + 1); case 'y': return dtend.getlyear () - dtStart.getFullYear();}}//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- this; var str = mydate.tolocaledatestring (); if (showweek) {var semaine = ['day', 'one', 'deux', 'trois', 'quatre', 'cinq', 'six']; str + = 'semaine' + semaine [mydate.getDay ()];} retour str;}//+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sdate = datestr.replace (/ (^ / s + | / s + $) / g, ''); // Retirez les espaces des deux côtés; if(sDate=='') return true;//If the format satisfies YYY-(/)MM-(/)DD or YYYY-(/)M-(/)DD or YYYY-(/)M-(/)D or YYYY-(/)MM-(/)D, it will be replaced with ''//In the database, the legal date can be: Yyyy-mm / dd (2003-3 / 21), et la base de données se convertira automatiquement au format Yyyy-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] {1} [/ d] {1} [/ d] {2 1,2} / g, ''); satisfait yyyy-mm-dd ou yyyy-m-dd ou yyyy-md ou yyyy-mm-d {var t = new Date (sdate.replace (// - / g, '/')); var ar = sdate.split (/ [- /::] /); if (ar [0]! = t.getyear () || ar [1]! = T.getron () + 1 | 2] AR [1]! = T.getron () + 1 | ! = t.getDate ()) {// alert ('Format de date de mauvaise date! Le format est: yyyy-mm-dd ou yyyy / mm / dd. Faites attention aux années.'); return false;}} else {// alert ('Format de date de mauvaise date! Le format est: yyyy-mm-dd ou yyyy / mm / dd. Faites attention aux années de saut. true;}//+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }): (/ 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.getearyear ()! = r [1]) 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; Vrai;} // + ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- MyDate.getDate (); MyArray [3] = MyDate.Gethours (); MyArray [4] = MyDate.getMinutes (); MyArray [5] = MyDate.getSecunds (); Return MyArray;} // + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- partiStr = ''; var semaine = ['day', 'one', 'deux', 'trois', 'quatre', 'cinq', 'six']; switch (interval) {case 'y': partiStr = mydate.getlyar (); casse; case 'm': partistr = mydate.getmonth () + 1; cass Semaine [mydate.getDay ()]; Break; case 'ww': partiStr = mydate.weeknumofyear (); break; case 'h': partiStr = mydate.Gethours (); Break; case 'n': partiStr = mydate.getMinutes (); Break; case 's': partiStr = mydate.getSeconds (); Break;} partStr;}//+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (nouvelle date (ary [0], ary [1] +1,1)); var date2 = date1.dateadd (1, 'm', 1); var result = datediff (date1.format ('yyyy-mm-dd'), date2.format ('yyyy-mm-dd'); return result;}//+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ MyDate.toArray (); var année = ary [0]; var mois = ary [1] +1; var day = ary [2]; document.write ('<script linguisse = vbscript /> /n') ;document.write('mydate = datevalue (' + mois + '-' + day + '-' + an '') /n' '' ;document.write. DatePart ('ww', mydate) / n '); document.write (' / n '); return Résultat;} // + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Convertir la chaîne Type // | Format mm / dd / yyyy mm-dd-yyy yyyy / mm / dd Yyyy-mm-dd // + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Date (Arys [0], - Arys [1], Arys [2]);} retourner mydate;}