Skip to main content

Intl

Tools for internationalization and localization. Create language-aware applications, handle date and time formatting, and adapt content for different locales.

Eg Intl

Interfaces

I
Intl.DateTimeFormatRangePart

Represents a part of a formatted date range produced by Intl.DateTimeFormat.formatRange().

I
Intl.Locale

Augments the standard Intl.Locale interface with members not yet present in the bundled TypeScript library definitions.

Namespaces

N
Intl

The Intl namespace groups the ECMAScript Internationalization API constructors and functions.

    Type Aliases

    T
    Intl.Formattable

    Types that can be formatted using Intl.DateTimeFormat methods.


      interface Intl.DateTimeFormat

      unstable

      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.DateTimeFormatRangePart

      unstable

      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
      readonly

      Returns the variant subtags of the locale as a single string, with subtags separated by -. Returns undefined if the locale has no variant subtags.

      MDN Reference


      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 #

      I
      Intl.DateTimeFormatRangePart

      Represents a part of a formatted date range produced by Intl.DateTimeFormat.formatRange().

      I
      Intl.Locale

      Augments the standard Intl.Locale interface with members not yet present in the bundled TypeScript library definitions.

      Type Aliases #

      T
      Intl.Formattable

      Types that can be formatted using Intl.DateTimeFormat methods.


        type alias Intl.Formattable

        unstable

        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 #


        Did you find what you needed?

        Privacy policy