Intl
Tools for internationalization and localization. Create language-aware applications, handle date and time formatting, and adapt content for different locales.
Eg Intl
interface Intl.DateTimeFormat
Methods
format(date?: Formattable | number): string Format a date into a string according to the locale and formatting options of this Intl.DateTimeFormat object.
formatToParts(date?: Formattable | number): globalThis.Intl.DateTimeFormatPart[] Allow locale-aware formatting of strings produced by Intl.DateTimeFormat formatters.
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.
formatRange(
startDate: Date | number,
endDate: Date | number,
): string formatRangeToParts<T extends Formattable>(
startDate: T,
endDate: T,
): DateTimeFormatRangePart[] Allow locale-aware formatting of tokens representing each part of the formatted date range produced by Intl.DateTimeFormat formatters.
formatRangeToParts(
startDate: Date | number,
endDate: Date | number,
): DateTimeFormatRangePart[] interface Intl.DateTimeFormatOptions
interface Intl.DateTimeFormatRangePart
Represents a part of a formatted date range produced by Intl.DateTimeFormat.formatRange().
Each part has a type and value that describes its role within the formatted string. The source property indicates whether the part comes from the start date, end date, or is shared between them.
Examples
const dtf = new Intl.DateTimeFormat('en', {
dateStyle: 'long',
timeStyle: 'short'
});
const parts = dtf.formatRangeToParts(
new Date(2023, 0, 1, 12, 0),
new Date(2023, 0, 3, 15, 30)
);
console.log(parts);
// Parts might include elements like:
// { type: 'month', value: 'January', source: 'startRange' }
// { type: 'day', value: '1', source: 'startRange' }
// { type: 'literal', value: ' - ', source: 'shared' }
// { type: 'day', value: '3', source: 'endRange' }
// ...
Properties
type: string The type of date or time component this part represents. Possible values: 'day', 'dayPeriod', 'era', 'fractionalSecond', 'hour', 'literal', 'minute', 'month', 'relatedYear', 'second', 'timeZoneName', 'weekday', 'year', etc.
value: string The string value of this part.
source:
"shared"
| "startRange"
| "endRange"
Indicates which date in the range this part comes from.
- 'startRange': The part is from the start date
- 'endRange': The part is from the end date
- 'shared': The part is shared between both dates (like separators)
interface Intl.Locale
Augments the standard Intl.Locale interface with members not yet present in the bundled TypeScript library definitions.
Properties
variants: string | undefined Returns the variant subtags of the locale as a single string, with subtags separated by -. Returns undefined if the locale has no variant subtags.
namespace Intl
The Intl namespace groups the ECMAScript Internationalization API constructors and functions.
This declaration augments the standard Intl namespace with members that are not yet part of the bundled TypeScript library definitions.
Interfaces
Represents a part of a formatted date range produced by Intl.DateTimeFormat.formatRange().
Augments the standard Intl.Locale interface with members not yet present in the bundled TypeScript library definitions.
Type Aliases
Types that can be formatted using Intl.DateTimeFormat methods.
type alias Intl.Formattable
Types that can be formatted using Intl.DateTimeFormat methods.
This type defines what values can be passed to Intl.DateTimeFormat methods for internationalized date and time formatting. It includes standard Date objects and Temporal API date/time types.
Examples
// Using with Date object
const date = new Date();
const formatter = new Intl.DateTimeFormat('en-US');
console.log(formatter.format(date));
// Using with Temporal types (when available)
const instant = Temporal.Now.instant();
console.log(formatter.format(instant));
Definition
© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/intl