formatHttpDate
Signature
Section titled “Signature”formatHttpDate(value: string): stringFormat 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
GMTsuffix 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
valueare 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’syear = 4DIGIT. - Compatibility: before 1.16.0 such years gave strings outside the grammar (
"00-1","275760"). For the value itself useTemporal.Instant#toString().
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | UTC ISO 8601 datetime string (e.g. “2024-03-15T14:30:00Z”) |
Returns
Section titled “Returns”RFC 9110 IMF-fixdate string, or "" on invalid input or a year outside 0000–9999
Examples
Section titled “Examples”import { formatHttpDate } from "@northguild/gmt/utc/format";
formatHttpDate("2024-03-15T14:30:00Z") // "Fri, 15 Mar 2024 14:30:00 GMT"