JS get current time (yesterday, today, tomorrow)

Source: Internet
Author: User
Tags time and seconds

1. The time control of some foreground pages in the development process we need to give the default current time, jquery can be easily implemented for us, the code is as follows:

//yesterday's TimevarDay1 =NewDate ();d ay1.settime (Day1.gettime ()-24*60*60*1000);varS1 = day1.getfullyear () + "-" + (Day1.getmonth () +1) + "-" +day1.getdate ();//Today's TimevarDay2 =NewDate ();d ay2.settime (Day2.gettime ());varS2 = day2.getfullyear () + "-" + (Day2.getmonth () +1) + "-" +day2.getdate ();//Tomorrow's TimevarDay3 =NewDate ();d ay3.settime (Day3.gettime ()+24*60*60*1000);varS3 = Day3.getfullyear () + "-" + (Day3.getmonth () +1) + "-" +day3.getdate ();//splicing TimefunctionShow () {varstr = "" + S1 + "to" +S2; returnstr;}//Assignment Doubledate$ (' #dateS '). Val (show ());

2. Here's how to get to the time and seconds

functionwritecurrentdate () {varnow =NewDate (); varYear = Now.getfullyear ();//Get year        varmonth = Now.getmonth ();//Get the Month        varDate = Now.getdate ();//Get Date        varDay = Now.getday ();//get a few weeks        varhour = Now.gethours ();//Get the Hour        varMinu = Now.getminutes ();//Get minutes        varSEC = Now.getseconds ();//Get seconds         varMS = Now.getmilliseconds ();//get milliseconds        varWeek; Month= month + 1; if(Month <) month = "0" +month; if(Date <) date = "0" +date; if(Hour <) hour = "0" +hour; if(Minu <) Minu = "0" +Minu; if(sec <) sec = "0" +sec; ifMs < MS = "0" +MS; varArr_week =NewArray ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); Week=Arr_week[day]; varTime = ""; time= year + "years" + month + "Month" + Date + "Day" + "+ Hour +": "+ Minu +": "+ sec +" +Week; //The current date is assigned to the current date input box (jQuery Easyui)$ ("#currentDate"). HTML (time); //sets the execution interval of the function that gets the current date, refreshed every 1000 milliseconds.         varTimer = SetTimeout ("Writecurrentdate ()", 1000); }

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.