method Intl.DateTimeFormat.formatRange
Overload 1
#DateTimeFormat.formatRange<T extends Formattable>(startDate: T,endDate: T,): string
Format a date range in the most concise way based on the locale and
options provided when instantiating this Intl.DateTimeFormat
object.
Examples #
#
const formatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'long' });
const startDate = new Date(2023, 0, 1);
const endDate = new Date(2023, 0, 5);
console.log(formatter.formatRange(startDate, endDate));
// Output: "January 1 – 5, 2023"
Type Parameters #
#T extends Formattable
Parameters #
Return Type #
string