format_date
Description
Converts a date object to a date string. Used to send data back to the server
format_date: (date: Date) => string;
Parameters
date- (required) Date - the date which needs formatting
Returns
text- (string) - a text representation of the date
Example
var dateToStr = gantt.date.date_to_str("%Y-%m-%d %H:%i");
gantt.templates.format_date = function(date){
return dateToStr (date);
};
Details
Check Date Format Specification.
Loading dates in ISO format
You can use ISO date format in Gantt. For this, you need to redefine functions that parse and serialize dates in Gantt:
gantt.templates.parse_date = function(date) {
return new Date(date);
};
gantt.templates.format_date = function(date) {
return date.toISOString();
};
Changing the date format dynamically
If you need to change the date format dynamically, it is necessary to modify the parse_date template in the following way:
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);
};