getTimeAgo
Signature
Section titled “Signature”getTimeAgo(units: Partial<Record<"hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds", number>>): stringReturn the PlainTime before now, as an ISO string, counted from the current time.
- Reads the clock once, after
unitsis checked. unitsis an object of unit amounts (hours to nanoseconds), such as{ minutes: 15 }. A duration string returns "". A fractional amount returns "": write{ minutes: 90 }for an hour and a half.- Lengths are unsigned: a negative amount returns "".
getTimeInis the other direction. - A date unit returns "", even at zero.
- Wraps at midnight and carries no day, so
getTimeAgo({ hours: 24 })is the time now. For a moment that keeps its date, usegetDateTimeAgoorgetZonedAgo. - Counts from now in the system time zone. Whole seconds, floored. For sub-second digits, use
subtractDateTime(getNow(), units), which also keeps the date. - Examples read the clock at 2027-06-15T12:00:00Z, with the system time zone UTC.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
units | Partial<Record<"hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds", number>> | unit amounts, such as { minutes: 15 }; never negative |
Returns
Section titled “Returns”ISO PlainTime string in whole seconds, or "" for invalid units, a date unit, a negative amount or an unavailable system zone
Related types
Section titled “Related types”Examples
Section titled “Examples”import { getTimeAgo } from "@northguild/gmt/plain/get";
getTimeAgo({ minutes: 15 }) // "11:45:00"Source
Section titled “Source”Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.