Javascript JSGantt甘特图-如何使用日期变量而不是文本

Javascript JSGantt甘特图-如何使用日期变量而不是文本,javascript,Javascript,我对Javascript比较陌生,一直在我的网站上使用JSGantt.js绘制甘特图。html页面上唯一需要的代码如下所示: <div style="position:relative" class="gantt" id="GanttChartDIV"></div> <script> // here's all the html code neccessary to display the chart object // Future idea

我对Javascript比较陌生,一直在我的网站上使用JSGantt.js绘制甘特图。html页面上唯一需要的代码如下所示:

<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
<script>
    // here's all the html code neccessary to display the chart object
    // Future idea would be to allow XML file name to be passed in and chart tasks built from file.

    var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'quarter');

    g.setShowRes(0); // Show/Hide Responsible (0/1)
    g.setShowDur(0); // Show/Hide Duration (0/1)
    g.setShowComp(0); // Show/Hide % Complete(0/1)
    g.setCaptionType('None');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
    g.setShowStartDate(0); // Show/Hide Start Date(0/1)
    g.setShowEndDate(0); // Show/Hide End Date(0/1)

    //var gr = new Graphics();

    if( g ) {
        // Parameters (pID, pName, pStart, pEnd,  pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption)
        // You can also use the XML file parser JSGantt.parseXML('project.xml',g)

        g.AddTaskItem(new JSGantt.TaskItem(1, 'Title',     '', '',  '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));

        g.Draw();   
        g.DrawDependencies();
    }
    else {
        alert("not defined");
    }
</script>
在g.AddTaskItem函数中,它期望在页面中键入一个日期。我想在它的位置使用现有的日期变量

我怎样才能做到这一点?谢谢你的帮助!如果您想查看获取此信息的.js文件,请参见:


假设它需要一个漂亮的ISO标准日期字符串,您可以这样做:

function getDate (days) {
     if (typeof days === "undefined") {
       var days = 0;
     }
     var date = new Date();
     return new Date(date.valueOf() + days*86400000).toISOString().substring(0,10);
}
<snip>
 g.AddTaskItem(new JSGantt.TaskItem(1, 'Title', getDate(-30), getDate(),  '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));
<snip>
getDate[可选数字]将返回今天的日期,并根据您给它的天数进行调整,或者如果没有给出参数,则返回今天的日期。理论上你可以在那里做任何功能。如果这不是正确的日期格式,可以使用toDateString或其他格式代替toISOString.substring0,10。如果需要,当然可以调整函数,甚至在运行时向用户询问日期