跳到主要内容

date_format

Description

指定用于解析数据集中日期以及向服务器发送日期时所使用的日期格式

date_format: string

Example

gantt.config.date_format = "%Y-%m-%d %H:%i";
...
gantt.init("gantt_here");
gantt.load("/data/tasks");

Default value: "%d-%m-%Y %H:%i"

Details

此配置选项用于创建 parse_dateformat_date 模板函数。 要使用自定义格式,你可以调整此配置值,或者直接重写 parse_dateformat_date 模板。

加载 ISO 格式的日期

Gantt 支持 ISO 日期格式。要启用此功能,需要重写负责解析和序列化日期的函数:

gantt.templates.parse_date = function(date) { 
return new Date(date);
};
gantt.templates.format_date = function(date) {
return date.toISOString();
};

动态更改日期格式

要动态更新日期格式,请按如下方式修改 parse_date 模板:

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);
};