JS date addition and subtraction, date calculation code _ time date-js tutorial

Source: Internet
Author: User
This article mainly introduces JS date addition and subtraction and date calculation code. For more information, see 1. date minus the number of days equals to the second date

Function cc (dd, dadd) {// you can add error processing var a = new Date (dd) a =. valueOf () a = a-dadd * 24*60*60 * 1000a = new Date (a) alert (. getFullYear () + "year" + (. getMonth () + 1) + "month" +. getDate () + "day")} cc ("12/23/2002", 2)

I have to add some resources here, wasting a lot of time to draw lessons:
Time code of Javascript
0-11: The number is 1-12 months. var a = new Date (, 6). The result is-6.
0-6 indicates the week
1-31 represents the date
0-23 hours
0-59 minutes, seconds

II. // Difference between two dates (d1-d2 ).

function DateDiff(d1,d2){  var day = 24 * 60 * 60 *1000;try{      var dateArr = d1.split("-");  var checkDate = new Date();    checkDate.setFullYear(dateArr[0], dateArr[1]-1, dateArr[2]);  var checkTime = checkDate.getTime();   var dateArr2 = d2.split("-");  var checkDate2 = new Date();    checkDate2.setFullYear(dateArr2[0], dateArr2[1]-1, dateArr2[2]);  var checkTime2 = checkDate2.getTime();    var cha = (checkTime - checkTime2)/day;     return cha;  }catch(e){  return false;}}//end fun

Iii. application:

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.