parse_date

将日期字符串转换为 Date 对象

datestring需要解析的字符串

Example

var cfg = gantt.config;
var strToDate = gantt.date.str_to_date(cfg.date_format, cfg.server_utc);
 
gantt.templates.parse_date = function(date){
    return strToDate(date);
};

Details

此函数在 gantt.load()gantt.parse() 过程中被调用,用于将任务的 start_date/end_date 字段从字符串转换为日期对象。
如果你使用的自定义格式是默认解析器无法处理的,可以重写此函数。更多细节请参见 日期格式规范

了解更多关于日期对象

以 ISO 格式加载日期

Gantt 支持 ISO 日期格式。要使用该格式,只需重写日期解析和格式化函数,如下所示:

gantt.templates.parse_date = function(date) { 
    return new Date(date);
};
gantt.templates.format_date = function(date) { 
    return date.toISOString();
};
See also
Back to top