Date Functions
const picker = new tempusdominus
.TempusDominus(document.getElementById('datetimepicker1'));
View Date
picker.viewDate
returns the pickers current view date.
picker.viewDate = DateTime
will set the view date, update the options and ask the view to refresh.
picker.dates
There are a number of function here that allow for retrieving the selected dates or adding to them.
These functions are used as picker.dates.add(...)
for example.
add(DateTime)
Adds a new DateTime to selected dates array. Use this function with caution. It will not automatically refresh the widget or do any validation.
setValue(value: DateTime, index?: number)
Sets the select date index (or the first, if not provided) to the provided DateTime object.
formatInput(value: DateTime): string
Formats a DateTime object to a string. Used when setting the input value. It is possible to overwrite this to provide more complex formatting with moment/dayjs or by hand.
parseInput(value:any): DateTime
Parse the value into a DateTime object. This can be overwritten to supply your own parsing.
setFromInput(value: any, index?: number)
Tries to convert the provided value to a DateTime object. If value is null|undefined then clear the value of the provided index (or 0). It is possible to overwrite this to provide more complex formatting with moment/dayjs or by hand.
isPicked(DateTime, Unit?)
Returns true if the target date is part of the selected dates array. If unit is provided then a granularity to that unit will be used.
pickedIndex(DateTime, Unit?)
Returns the index at which target date is in the array. This is used for updating or removing a date when multi-date is used. If unit is provided then a granularity to that unit will be used.