date
a set of date formatting methods
object date;
Details
The date object provides the following methods:
-
add (date, number, unit): Date - adds/subtracts the specified time interval to/from the date
- date - (Date) the date object that you need to add a time to/subtract a time from
- number - (number) the number of units to add. If this number is positive - the time will be added to the date, if negative - the time will be subtracted
- unit - (string) the time unit. Values: 'minute', 'hour', 'day', 'week', 'month', 'year'.
//adds 1 year to the specified date: 29 June, 2019 -> 29 June, 2020
var newDate = gantt.date.add(new Date(2019, 05, 29), 1, 'year');
add_quarter (date, number): Date - adds/subtracts the specified number of quarters to/from the date
- date - (Date) the date object that you need to add quarters to/subtract quarters from
- number - (number) the number of quarters (1 quarter = 3 months) to add. If this number is positive - the quarters will be added to the date, if negative - the quarters will be subtracted
//adds 1 quarter (3 months) to the specified date:
//29 June, 2019 -> 29 September, 2020
var newDate = gantt.date.add_quarter(new Date(2019, 05, 29), 1);
convert_to_utc (date): Date - converts local time to UTC
- date - (Date) the date object to convert
//29 June, 2019 14:00 (local time) -> 29 June, 2019 12:00 (utc)
var time = gantt.date.convert_to_utc(new Date(2019, 05, 29, 14, 00));
copy (date): Date - makes a copy of a Date object
- date - (Date) the date object to copy
var copy = gantt.date.copy(new Date(2019, 05, 29));// -> 29 June, 2019
date_part (date): Date - resets the time part of the provided date to 00:00:00
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 29 June, 2019 00:00:00
var date = gantt.date.date_part(new Date(2019, 05, 29, 14, 30, 10));
date_to_str (format, utc): Function - returns a function that converts a Date object to a string of the specified format
- format - (string) the date format ( see Date Format Specification)
- utc? - (boolean) specifies whether local time should be converted to UTC
var formatFunc = gantt.date.date_to_str("%d/%m/%Y");
var date = formatFunc(new Date(2019, 05, 29)); // -> "29/06/2019"
day_start (date): Date - resets the time part of the provided date to 00:00:00. Alias of the date_part method. Used by the Day view to set the display date and can be redefined to provide the default behaviour
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 29 June, 2019 00:00:00
var date = gantt.date.day_start(new Date(2019, 05, 29, 14, 30, 10));
getISOWeek (date): number - returns the ISO-8601 week number of the date, weeks starts on Monday
- date - (Date) the date object to format
var week = gantt.date.getISOWeek(new Date(2019, 05, 29));// ->26
getUTCISOWeek (date): number - returns the week number of the date, but previously converts local time to UTC
- date - (Date) the date object to format
var week = gantt.date.getUTCISOWeek(new Date(2019, 05, 29));// ->26
getWeek (date): number - returns the week number of the date. Weeks start either on Monday or Sunday, depending on the value of the start_on_monday property.
- date - (Date) the date object to format
// weeks start on Sunday
gantt.config.start_on_monday = false;
var isoWeek = gantt.date.getISOWeek(new Date(2019, 2, 25)); // ->12
var week = gantt.date.getWeek(new Date(2019, 2, 25)); // ->13
month_start (date): Date - returns a Date object of the first day of the month for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 01 June, 2019 00:00
var firstDay = gantt.date.month_start(new Date(2019, 05, 29, 14, 30));
parseDate (date, format): Date - converts a string of the specified format to a Date object
var date = gantt.date.parseDate("29/06/2019","%d/%m/%Y");//-> 29 June, 2019 00:00:00
str_to_date (format, utc): Function - returns a function that converts a string of the specified format to a Date object
- format - (string) the date format ( see Date Format Specification)
- utc? - (boolean) specifies whether local time should be converted to UTC
var formatFunc = gantt.date.str_to_date("%d/%m/%Y");
var date = formatFunc("29/06/2019"); // -> 29 June, 2019 00:00:00
time_part (date): number - returns the time of a Date object as a number of seconds counted from the midnight (00:00:00)
- date - (Date) the date object to format
var time = gantt.date.time_part(new Date(2019, 05, 29, 14, 30, 10));
to_fixed (num): string - adds the leading zero to numbers less than 10 and returns the result as a string. Doesn't affect numbers from 10
- num - (number) the number to format
var num1 = gantt.date.to_fixed(2);// ->"02"
var num2 = gantt.date.to_fixed(10);// ->10
minute_start (date): Date - returns a Date object of the specified date and clears the part with seconds to zero
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 29 June, 2019 14:30:00
var date = gantt.date.minute_start(new Date(2019, 05, 29, 14, 30, 10));
hour_start (date): Date - returns a Date object of the specified date and clears the part with minutes and seconds to zero
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 29 June, 2019 14:00:00
var date = gantt.date.hour_start(new Date(2019, 05, 29, 14, 30, 10));
week_start (date): Date - returns a Date object of the first day of the week for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 24 June, 2019 00:00
var weekStart = gantt.date.week_start(new Date(2019, 05, 29, 14, 30));
quarter_start (date): Date - returns a Date object of the first month of the quarter for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 01 April, 2019 00:00:00
var date = gantt.date.quarter_start(new Date(2019, 05, 29, 14, 30, 10));
year_start (date): Date - returns a Date object of the first day of the year for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 01 January, 2019 00:00
var yearStart = gantt.date.year_start(new Date(2019, 05, 29, 14, 30));
Back to top