Spec-Zone.ru › Deno 2

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

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

unstable

Properties

dayPeriod:
"narrow"
| "short"
| "long"
optional
dateStyle:
"full"
| "long"
| "medium"
| "short"
optional
timeStyle:
"full"
| "long"
| "medium"
| "short"
optional

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

Intl.DateTimeFormat
No documentation available
  • format
  • formatRange
  • formatRangeToParts
  • formatToParts
Intl.DateTimeFormatOptions
No documentation available
  • dateStyle
  • dayPeriod
  • timeStyle
Intl.DateTimeFormatRangePart

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

  • source
  • type
  • value
Intl.Locale

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

  • variants

Type Aliases

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

Date
| Temporal.Instant
| Temporal.ZonedDateTime
| Temporal.PlainDate
| Temporal.PlainTime
| Temporal.PlainDateTime
| Temporal.PlainYearMonth
| Temporal.PlainMonthDay

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/intl

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API