Nodes/JNComfy/Timedelta Format
ComfyUI Node

Timedelta Format

Turn 'how long it took' into a string you'd actually show someone

By jn-jairo·Created 2 years ago·Updated 2 years ago· 5
Timedelta Format
  • value
  • STRING
str_format

Every once in a while you want to know - and show - how long something took. ComfyUI has no built-in "elapsed time" node, which is why packs keep shipping their own datetime families. JNComfy's version is a small cluster (JN_DatetimeNow, JN_TimedeltaInfo, JN_TimedeltaFormat…), and this node is the one that turns a duration into a readable string. Feed it a TIMEDELTA value and a format, get back a STRING like "Took 00:12:34".

How it works

The format is a template with five placeholders, replaced literally:

  • %d - days (not zero-padded)
  • %H - hours, zero-padded to 2
  • %M - minutes, zero-padded to 2
  • %S - seconds, zero-padded to 2
  • %f - microseconds, zero-padded to 6

So str_format of "%d days %H:%M:%S" on a duration of one day, 12 hours and change gives "1 days 12:34:56". The placeholders are replaced one pass at a time, left to right - nothing clever like strftime, just five named tokens.

  • value - a TIMEDELTA. This is a type the pack defines; the natural source is the DATETIME output of JN_DatetimeNow fed into a JN_MathOperation with a - b (subtracting two datetimes in Python yields a timedelta), or anything else in the pack's datetime family that hands you a duration.
  • str_format - your template. The % tokens are the only thing that gets substituted.

Output is a STRING, so it plugs into text nodes, filename builders, or JN_Dump.

Where you'd use it

Mostly logging and labels. Capture JN_DatetimeNow at the start and end of a workflow, subtract, and format the result to print how long the run took - either to the console or baked into an output filename. It's also handy for building human-readable timeout/duration strings out of computed values. If you need the raw numbers instead of a string, JN_TimedeltaInfo breaks a timedelta into separate days, hours, minutes, seconds, microseconds, and total_seconds outputs.

Install

Part of JNComfy. ComfyUI Manager → search "JNComfy" → Install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/jn-jairo/jn_comfyui

restart, and pip install -r requirements.txt inside the folder if you're installing manually. It's pure Python; the pack's big requirements list (torchaudio, librosa, transformers…) belongs to the audio/face-restore sections and has nothing to do with this node.

Gotchas

  • It's not strftime. %Y, %m, %j and friends will pass through unchanged because they're not in the list of five. If you try %Y-%m-%d you'll literally see those tokens in the output. That's the top mistake.
  • %d is days, not day-of-month. It's a duration formatter, so %d means elapsed days - "2 days" for a two-day timedelta, not "the 2nd".
  • Getting a TIMEDELTA into this node isn't always obvious since none of the pack's nodes output that type directly - the * output of a JN_MathOperation subtraction (two JN_DatetimeNow values, a - b) is the practical route. Feed it something that isn't a timedelta and the formatting will fail or print garbage.
CategoryJN/Other

Inputs (2)

NameTypeDefaultDescription
valueTIMEDELTA
str_formatSTRING

Outputs (1)

NameTypeDescription
STRINGSTRING