JS Get the current time (yesterday, today, tomorrow) _javascript tips

Source: Internet
Author: User
Tags getdate

This example for you to share the current time JS to obtain the specific code for your reference, the specific content as follows

JS get current time (Yesterday, Today, tomorrow)

Time controls for some foreground pages in the development process we need to give the default current time, jquery can easily help us implement the code as follows

Yesterday's time
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 ();
Stitching time
function Show () {
  var str = "" + S1 + "to" + S2;
  return str;
}
Assignment doubledate
 $ (' #dateS '). Val (show ());

The following is a specific time to get the method of seconds

function Writecurrentdate () {var now = new Date (); var year = Now.getfullyear ();  Get year var month = Now.getmonth ();//Get month var date = Now.getdate ();//Get date var day = Now.getday ();//Get weeks Var hour = now.gethours ()//Get hour var minu = Now.getminutes ();//Get minutes var sec = now.getseconds ();//Get second var MS = no
    W.getmilliseconds ()//Get millisecond Var week;
    Month = month + 1;
    if (Month <) month = "0" + month;
    if (date < ten) date = "0" + date;
    if (hour <) hour = "0" + hour;
    if (Minu <) Minu = "0" + minu;
    if (sec <) sec = "0" + sec;
    if (MS < MB) ms = "0" + ms;
    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;
    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, and refreshes every 1000 milliseconds. var timer = settimeout ("Writecurrentdate ()", 1000); }

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.