valFormat()
Get / set a formatted value for the instance.
Please note - this property requires the DateTime extension for DataTables.
Description
This method can be used to get or set the value for the DateTime instance, in a specific format. For example, it can be used to set a value given in a format that is not ISO8601, or you could read back a value in some other format (i.e. a localised human readable format).
The formatting options available will depend upon the date / time library being used (e.g. Moment.js or Luxon).
Types
function valFormat(format)
- Description:
Get the value of the DateTime instance.
- Parameters:
Name Type Optional 1 format
No The format that you want the date/time value in.
- Returns:
The formatted value.
Examples
Get a value from the input with a specific format:
let el = document.getElementById('example');
let dt = new DateTime(el);
el.addEventListener('change', function () {
console.log('Selected value is: ', dt.valFormat('MM-DD-YYYY'));
});
Set a value into the input from a formatted string:
let dt = new DateTime(document.getElementById('example'));
dt.valFormat('MM-DD-YY', '03-02-23');