For custom-delimited date formats, you have to pull out the date (or time) components from a DateTimeFormat
object (which is part of the ECMAScript Internationalization API), and then manually create a string with the delimiters you want.
To do this, you can use DateTimeFormat#formatToParts
. You could destructure the array, but that is not ideal, as the array output depends on the locale:
{ // example 1
let formatter = new Intl.DateTimeFormat('en');
let example = formatter.formatToParts();
console.log(example);
}
{ // example 2
let formatter = new Intl.DateTimeFormat('hi');
let example = formatter.formatToParts();
console.log(example);
}