Js get the specified date (today, yesterday, the day after tomorrow), js get

Source: Internet
Author: User

Js get the specified date (today, yesterday, the day after tomorrow), js get

Js obtains the specified date (today, yesterday, and the day after tomorrow), and uses js to obtain a specified date, such as today and tomorrow.

Function getDate (AddDayCount) {var dd = new Date (); dd. setDate (dd. getDate () + AddDayCount); // obtain the date var y = dd after AddDayCount. getFullYear (); var m = dd. getMonth () + 1; // obtain the date var d = dd of the current month. getDate (); return y + "-" + (m <10? "0" + m: m) + "-" + (d <10? "0" + d: d );}

Here, AddDayCount refers to the date from today, 0 indicates today, and 1 indicates tomorrow;

GetFullYear () gets the Year;

GetMonth () + 1; // get the date of the current month

GetDate (); get the date number;

Because the obtained value is an integer, the standard format of yyyy-MM-dd is not obtained. Therefore, we need to judge m <10? "0" + m: m.

Related Article

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.