<Script> // a Date () object is a date must use the new constructor to call our creation date object var arr = new Array (); // create an array object var obj = new Object (); // create an object instance // 1. Date parameter returns the current time if there is no current system var DATE = new new Date (); the console.log (DATE); // 2. numeric parameters common wording 2019, 10, 01 or string '2019-10-1. 8:. 8:. 8' var date1 = new new a Date (2019, 10,. 1 ); the console.log (date1); // return is not October November var DATE2 = new new a Date ( '2019-10-18: 8: 8'); console.log(date2); </script>
<Script> // format date date var DATE = new new a Date (); the console.log (the Date.getFullYear ()); // returns the current date in 2019 the console.log (date.getMonth () +. 1) ; // small returned a month month month month +1 remember Yo console.log (date.getDate ()); // return is the date console.log (date.getDay ()); // 3 return on Monday 1 is returned on Saturday, but Sunday is 6 returns 0 // we wrote a May 2019 Wednesday 1st var year = Date.getFullYear (); var month the date.getMonth = () + 1 ; var a dates = date.getDate (); vararr = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; var Day = date.getDay (); console.log ( 'Today is: '+ year +' of '+ month +' month '+ dates +' date '+ ARR [day]); </ Script>
<Script> // when formatting date Minutes var DATE = new new a Date (); console.log (date.getHours ()); // time console.log (date.getMinutes ()); // sub console.log ( date.getSeconds ()); // s // packaging requirements a function that returns the current time, hour 08:08:08 function the getTimer () { var time = new new a Date (); var H = time.getHours (); H H = <10 '0' +? H: H; var m = time.getMinutes (); m= m < 10 ? '0' + m : m; var s = time.getSeconds(); s = s < 10 ? '0' + s : s; return h + ':' + m + ':' + s; } console.log(getTimer()); </script>
<Script> // get the total number of milliseconds Date (timestamp) time in milliseconds rather than the current through the number of milliseconds from January 1, 1970 @ 1. valueOf () the getTime () var DATE = new new DATE (); console.log (date.valueOf ()); // is our time now distance 1970.1.1 total number of milliseconds console.log (date.getTime ()); // 2. simple wording (most commonly wording) var date1 + = new new a Date (); // + new new a Date () returns the total number of milliseconds is console.log (date1); // 3. the total number of milliseconds to obtain the H5 new console.log ( Date.now ()); </ Script>
<Script> // countdown effect // 1. Core algorithm: subtracting the input time is the time now remaining time, i.e. countdown, but not holding the minutes and seconds are subtracted, such as by subtracting 05 minutes 25 minutes, the result will be negative numbers. // 2. do with a time stamp. Total time of the user input minus the whole number of milliseconds milliseconds now, the number of milliseconds is obtained remaining time. // 3. The total remaining number of milliseconds to convert days, hours, minutes, seconds (minutes and seconds into the time stamp) // conversion formula is as follows: @ D = the parseInt (total seconds / 60/60 / 24) ; // number of days @ H = the parseInt (total seconds / 24%, 60/60) // calculate h // m = the parseInt (total seconds / 60% 60); // score calculation // S = the parseInt ( 60% of the total number of seconds); // calculate the current second function the countDown (time) { var nowtime + = new new a Date (); // returns the current time is the total number of milliseconds var inputTime = +new new a Date (Time); // returns the total number of user input time in milliseconds var Times = (inputTime - nowtime) / 1000; // Times is the total number of seconds remaining time var D = the parseInt (Times / 60/60 / 24); // day D = D <10 '0' +? D: D; var H = the parseInt (Times / 60/60 24%); // time ? H = H <10 '0' + H: H ; var m = the parseInt (Times / 60% 60); // points m = m <10 '0' +? m: m; var S = the parseInt (Times 60%); // current second s = s <10 ? '0' + s : s; return d + '天' + h + '时' + m + '分' + s + '秒'; } console.log(countDown('2019-5-1 18:00:00')); var date = new Date(); console.log(date); </script>