Skip to content

formatHttpDate

formatHttpDate(value: string): string

Format a UTC ISO 8601 datetime string as an HTTP header date — the RFC 9110 IMF-fixdate that headers like Last-Modified/Date/Expires require.

  • Fixed grammar, not a display format. RFC 9110 mandates English weekday/month abbreviations and a literal GMT suffix regardless of caller locale — there is no locale-appropriate alternative ordering to lose.
  • Always GMT; HTTP-date carries no offset variation to preserve.
  • Fractional seconds in value are truncated — IMF-fixdate has no sub-second field.
  • Day, hour, minute, and second are always zero-padded to 2 digits; year is zero-padded to 4 digits.
  • Returns "" for a year outside 0000–9999: IMF-fixdate’s year = 4DIGIT.
  • Compatibility: before 1.16.0 such years gave strings outside the grammar ("00-1", "275760"). For the value itself use Temporal.Instant#toString().
ParameterTypeDescription
valuestringUTC ISO 8601 datetime string (e.g. “2024-03-15T14:30:00Z”)

RFC 9110 IMF-fixdate string, or "" on invalid input or a year outside 0000–9999

import { formatHttpDate } from "@northguild/gmt/utc/format";
formatHttpDate("2024-03-15T14:30:00Z") // "Fri, 15 Mar 2024 14:30:00 GMT"
output 

utc/format/formatHttpDate.ts