effect-io-ai

Package: effect
Module: DateTime

DateTime.formatUtc

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"

Signature

declare const formatUtc: { (options?: (Intl.DateTimeFormatOptions & { readonly locale?: string | undefined; }) | undefined): (self: DateTime) => string; (self: DateTime, options?: (Intl.DateTimeFormatOptions & { readonly locale?: string | undefined; }) | undefined): string; }

Source

Since v3.6.0