0

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?

corvid
  • 10,733
  • 11
  • 61
  • 130
  • 1
    This might help: [Format a duration from seconds using date-fns](https://stackoverflow.com/questions/48776140/format-a-duration-from-seconds-using-date-fns) – majusebetter Sep 20 '22 at 12:55
  • It seems like you might want the relative time format method from Intl? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat – evolutionxbox Sep 20 '22 at 12:58

0 Answers0