Js get current time (yesterday, today, tomorrow)

Source: Internet
Author: User
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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.