Hyperlinkv0.8.0-beta.28

DateTime

DateTime.formatUtcconsteffect/DateTime.ts:2606
(
  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 using the UTC time zone.

Details

This forces the time zone to be UTC.

Example (Formatting DateTime values in UTC)

import { DateTime } from "effect"

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

// Force UTC formatting regardless of time zone
const utcFormatted = DateTime.formatUtc(dt, {
  year: "numeric",
  month: "2-digit",
  day: "2-digit",
  hour: "2-digit",
  minute: "2-digit",
  timeZoneName: "short"
})

console.log(utcFormatted) // "06/15/2024, 02:30 PM UTC"
formatting
export const formatUtc: {
  (
    options?:
      | Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      }
      | undefined
  ): (self: DateTime) => string
  (
    self: DateTime,
    options?:
      | Intl.DateTimeFormatOptions & {
        readonly locale?: string | undefined
      }
      | undefined
  ): string
} = Internal.formatUtc