deno.com

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 #

#startDate: T

The start date of the range to format.

#endDate: T

The start date of the range to format. Must be the same type as startRange.

Return Type #

string

Overload 2

#DateTimeFormat.formatRange(
startDate: Date | number,
endDate: Date | number,
): string

Parameters #

#startDate: Date | number
#endDate: Date | number

Return Type #

string