[Dbw]js Get current time (yesterday, today, tomorrow)

Source: Internet
Author: User
Tags time and seconds

  1. In the development process some of the foreground page time control we need to give the default current time, jquery can easily help us implement, the code is as follows
    1//Yesterday's time 2 var day1 = new Date (); 3 Day1.settime (Day1.gettime () -24*60*60*1000); 4 var S1 = day1.getfullyear () + "-" + (Day1.getmonth () +1) + "-" + day1.getdate (); 5//Today's time 6 var day2 = new Date (); 7 Day2.settime (Day2.gettime ()); 8 var s2 = day2.getfullyear () + "-" + (Day2.getmonth () +1) + "-" + day2.getdate (); 9//Tomorrow's time: var day3 = new Date (), Day3.settime (Day3.gettime () +24*60*60*1000), var s3 = Day3.getfullyear () + "-" + (day3  . GetMonth () +1) + "-" + day3.getdate (); 13//Splicing time function Show () {$      var str = "" + S1 + "to" + s2;16      return str;17 }18//Assign Value DOUBLEDATE19  $ (' #dateS '). Val (show ());        

  2. Here's how to get to the time and seconds
     1 function Writecurrentdate () {2 var now = new Date (), 3 var year = Now.getfullyear ();         var month = Now.getmonth ();//Get month 5 var date = Now.getdate ();//Get date 6 var day = Now.getday ();//Get Week 7 var hour = now.gethours ();//Get hour 8 var minu = Now.getminutes ();//Get minutes 9 var sec = Now.getseconds (); To the second of var MS = Now.getmilliseconds ();//Gets the millisecond one-by-one var week;12 month = month + 1;13 if (month &lt ;         month = "0" + month;14 if (date <) date = "0" + date;15 if (hour < ten) hour = "0" + hour;16  if (Minu <) Minu = "0" + minu;17 if (sec <) sec = "0" + sec;18 if (MS < +) ms = "0" + ms;19 var arr_week = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), week = Arr_week[day] * var time = "", "time = year +" years "+ month +" Month "+ Date +" Day "+" "+ Hour +": "+ Minu +": "+ sec +         "" + week;23The current date is assigned to the current date input box (JQuery Easyui) $ ("#currentDate"). HTML (time); 25//Set the execution interval of the function that gets the current date, refreshed every 1000 milliseconds. $ var timer = setTimeout ("Writecurrentdate ()", 1000); 27}

    D

[Dbw]js Get current time (yesterday, today, tomorrow)

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.