Hyperlinkv0.8.0-beta.28

DateTime

DateTime.formatconsteffect/DateTime.ts:2512
(
  options?:
    | (Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      })
    | undefined
): (self: DateTime) => string
(
  self: DateTime,
  options?:
    | (Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      })
    | undefined
): string

Formats a DateTime with Intl.DateTimeFormat.

Details

Unless a timeZone option is supplied, UTC values are formatted in UTC and zoned values are formatted in their named zone or fixed-offset zone.

Fixed-offset zones depend on runtime support for offset timeZone identifiers. When unsupported, formatting falls back to UTC with the DateTime adjusted to the offset.

Example (Formatting DateTime values with Intl options)

import { DateTime } from "effect"

const dt = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", {
  timeZone: "Europe/London"
})

const formatted = DateTime.format(dt, {
  dateStyle: "full",
  timeStyle: "short",
  locale: "en-US"
})

console.log(formatted) // "Saturday, June 15, 2024 at 3:30 PM"
formatting
export const format: {
  (
    options?:
      | Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      }
      | undefined
  ): (self: DateTime) => string
  (
    self: DateTime,
    options?:
      | Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      }
      | undefined
  ): string
} = Internal.format