Js obtains the time control of some front-end pages during the development process of the current time (yesterday, today, and tomorrow). We need to set the default time. jquery can help us easily implement the time control. The Code is as follows:
// The Time of yesterday var day1 = new Date (); day1.setTime (day1.getTime ()-24*60*60*1000); var s1 = day1.getFullYear () + "-" + (day1.getMonth () + 1) + "-" + day1.getDate (); // Today's time var day2 = new Date (); day2.setTime (day2.getTime (); var s2 = day2.getFullYear () + "-" + (day2.getMonth () + 1) + "-" + day2.getDate (); // tomorrow's time var day3 = new Date (); day3.setTime (day3.getTime () + 24*60*60*1000); var s3 = day3.getFullYear () + "-" + (day3.getMonth () + 1) + "-" + day3.getDate (); // splicing time function show () {var str = "" + s1 + "to" + s2; return str;} // value doubleDate $ ('# dates '). val (show ());
The following describes how to obtain the time, minute, and second information.
Function writeCurrentDate () {var now = new Date (); var year = now. getFullYear (); // get the year var month = now. getMonth (); // obtain the month var date = now. getDate (); // obtain the date var day = now. getDay (); // obtain the number of weeks var hour = now. getHours (); // get the hour var minu = now. getMinutes (); // get the minute var sec = now. getSeconds (); // get the second var MS = now. getMilliseconds (); // get the millisecond var week; month = month + 1; if (month <10) month = "0" + month; if (date <10) date = "0" + date; if (hour <10) hour = "0" + hour; if (minu <10) minu = "0" + minu; if (sec <10) sec = "0" + sec; if (MS <100) MS = "0" + MS; var arr_week = new Array ("Sunday ", "Monday", "Tuesday", "Wednesday", "Thursday", "Saturday"); week = arr_week [day]; var time = ""; time = year + "year" + month + "month" + date + "day" + "+ hour +": "+ minu + ": "+ sec +" "+ week; // the current date is assigned to the current date input box (jQuery easyUI) $ (" # curr EntDate "interval .html (time); // set the execution interval of the function on the current date, which is refreshed every 1000 milliseconds. Var timer = setTimeout ("writeCurrentDate ()", 1000 );}