I want to show a timer in the format HH:mm:ss
, where that is a "countdown" to some target time. My first thought was to use intervalToDuration
because of its description:
An object that combines two dates to represent the time interval.
function getTimeUntilEventStart(eventTime: Date, timeZone: string) {
return intervalToDuration({
start: utcToZonedTime(new Date(), timeZone),
end: eventTime,
});
}
However, when I have it as a duration, there doesn't seem to be any formatting options other than formatDistance
and formatDistanceToNow
, which format it in the form 1 hour from now
Is there a way to get the distance from now in an arbitrary user-defined format?