代码之家  ›  专栏  ›  技术社区  ›  Hector Minaya

使用jQuery为日期添加月份

  •  1
  • Hector Minaya  · 技术社区  · 16 年前

    <%= Html.TextBox("FechaInicio") %>
    

    <%= Html.TextBox("Meses") %>
    

    3 回复  |  直到 16 年前
        1
  •  2
  •   Justin Johnson    16 年前

    FechaInicio year , month day Meses .

    // Magical parsing of `FechaInicio` here
    var year = 2010, month = 9, day = 14;
    // The value of `meses`
    var meses_mas = 3;
    
    var future_date = new Date(year, month + meses_mas, day);
    
    console.log(future_date);
    

    你最终会得到 Wed Apr 14 2011 00:00:00 GMT-0700 (PST)

    此外作为旁注, Date

        2
  •  0
  •   Myles    16 年前

    var startDate = parseDate();
    var monthsToAdd = getMonthsToAdd();
    
    while (startDate.getMonth() + monthsToAdd > 11) {
      startDate.setFullYear(startDate.getFullYear() + 1);
      monthsToAdd - 11;
    }
    
    startDate.setMonth(startDate.getMonth() + monthsToAdd);
    
        3
  •  0
  •   Allen Wang    16 年前
            var numofMonthtoAdd = 5; //number of month you may want to add
    
            var beginDate = new Date();
            var month = (parseInt(beginDate.getMonth()) + parseInt(numofMonthtoAdd )) % 12;
            var year = (parseInt(beginDate.getMonth()) + parseInt(numofMonthtoAdd )) / 12;
            beginDate.setMonth(month);
            beginDate.setFullYear(parseInt(beginDate.getFullYear()) + year );
            return beginDate;