- Supported Minecraft Versions
This script allows you to format timespans in a similar way to how you can format dates (%date% formatted as "hh:mm:ss").
the main function is formatTimespan(timespan, format, trim-zeroes).
you give it your timespan, optionally a format string, and optionally a boolean to trim leading zeroes.
formatTimespan((1 hour, 1 minute, 1 second)) -> "01:01:01"
By default, the format is "hh:mm:ss", but you can change it to whatever you want. (see the on load event if you want to edit the default).
The number of characters in the format string determines the padding of the output. For example, "mm" means that there will always be at least two digits "01", "15", "159", etc.
The script will automatically add more digits as required, but it will never use less digits than what you tell it to.
The default names of the denominations are as follows:
t: millisecond (1 tick = 50 ms)
You can change these in the on load event as well, just make sure they don't overlap.
If you want to add text into the format without it being treated as time symbols, you can use the $ character.
anything within $...$ will be ignored by the script, and will be copied into the output. Doubling the $ will result in a single $ in the output.
formatTimespan((1 hour, 1 minute, 1 second), "hh$h$, mm$m$, ss$s left!$") -> "01h, 01m, 01s left!"
Finally, trim-zeroes will remove leading zeroes from the output. This is useful if you don't want to show hours if the timespan is less than an hour, for example.
Be warned that this removes *everything* before the first number. If you have text before the first number, it will be removed as well. It will stop at 0.xxx, however, so you can use decimals.
formatTimespan((1 minute, 1 second), "hh:mm:ss", true) -> "1:01"
If you have any questions, make a post in SkUnity discord and tag me: sovde#0001, but make it clear you're asking about this script!