Date automatically calculates time

Source: Internet
Author: User
 

A convenient method for date arithmetic. This method does not change the date instance itself, but instead returns a ...

A convenient method for date arithmetic. Instead of changing the date instance itself, this method returns a new instance of the date object created with the result of the operation. For example:

Basic usage:
var dt = new Date (' 10/29/2006 '). Add (Date.day, 5);
document.write (DT); Return ' Fri Oct 2006 00:00:00 '

//negative number will be subtracted from the value:
var dt2 = new Date (' 10/1/2006 '). Add (Date.day,-5);
document.write (DT2); Return ' Tue Sep 2006 00:00:00 '

//You can even call this method several times in a row
var dt3 = new Date (' 10/1/2006 '). Add (Date.day, 5). Add (Date.hour, 8). Add (Date.minute, -30);
document.write (DT3); Back to ' Fri Oct 06 2006 07:30:00 '
 

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.