JS Count dates based on number of days

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<meta http-equiv= "Content-type" content= "text/html; charset=windows-1250 ">
<meta name= "generator" content= "PSPad editor, www.pspad.com" >
<title></title>
<body>

<script type= "Text/javascript" >

Alert (Showdate (20));

function Showdate (calvalue) {

var dateobj = new Date ();
var curyear = Dateobj.getfullyear ();
var curmonth = dateobj.getmonth () + 1;
var curdate = Dateobj.getdate ();

Curmonth = curmonth > 9? Curmonth: "0" + curmonth;
Curdate = curdate > 9? Curdate: "0" + curdate;
var dateparameter = curyear + "/" + Curmonth + "/" + curdate;
var returndate = "";
Returndate = Calculatedate (Dateparameter, Calvalue);

return returndate;
}

function Calculatedate (Dateparameter, Calvalue) {
var calvalue = number (Calvalue);
var newdate = new Date (dateparameter);
Returns the millisecond value of a date
Newdate = Newdate.valueof ();
Millisecond value after plus/minus number of days
Newdate = newdate + calvalue * 24 * 60 * 60 * 1000;
Newdate = new Date (newdate);

If the month length is less than 2, the top plus 0 complements
var month = Newdate.getmonth () +1;
var month = month > 9? Month: "0" + month;

If the number of days is less than 2, the front plus 0 is the complement
var date = Newdate.getdate ();
var date = date > 9? Date: "0" + date;

var returndate = newdate.getfullyear () + "-" + month + "-" + date;
return returndate;
}

</script>
</body>

JS Count dates based on number of days

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.