1

我有一个带有值的输入字段 ReportTimeFrom09.07.2013我如何将一周添加到该日期?

我用

$("#ReportTimeFrom").val()

获得价值

4

2 回答 2

1

试试下面这个例子并检查 jSfiddle -> http://jsfiddle.net/ApfJz/13/

function parseDate(input) {
  var parts = input.split('.');
  return new Date(parts[2], parts[1]-1, parts[0]); // months are 0-based
}

$('#change').click(function () {
   var date = parseDate($("#ReportTimeFrom").val());

    // add one week to date
    date.setDate(date.getDate() + 7); 

    $('#ReportTimeFrom').val(("0" + date.getDate()).slice(-2) + '.' + (("0" + (date.getMonth() + 1))).slice(-2) + '.' + date.getFullYear());

});  
于 2013-07-16T07:09:22.277 回答
0

您可以使用此功能

var dmy = $("#ReportTimeFrom").val().split("/"); // "24/06/2011" should be pulled from $("#DatePicker").val() instead
console.log($("#ReportTimeFrom").val());
var joindate = new Date(
    parseInt(dmy[2], 10),
    parseInt(dmy[1], 10) - 1,
    parseInt(dmy[0], 10)
);
console.log(joindate); // Fri Jun 24 2011 00:00:00 GMT+0500 (West Asia Standard Time) 
joindate.setDate(joindate.getDate() + 7); // substitute 1 with actual number of days to add
//$("#ReportTimeFrom").val(joindate)
console.log(joindate);
console.log(
    ("0" + joindate.getDate()).slice(-2) + "/" +
    ("0" + (joindate.getMonth() + 1)).slice(-2) + "/" +
    joindate.getFullYear());

工作演示小提琴

于 2013-07-16T07:19:39.617 回答