Resource icon
  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Supported Minecraft Versions
  1. 1.17
  2. 1.18
  3. 1.19
  4. 1.20
Requires SkBee for the ticks of %timespan% expression, though this could be swapped out for skript-reflect or another addon.

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.

ex:
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:
y: year
o: month
w: week
d: day
h: hour
m: minute
s: second
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.

ex:
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.

ex:
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!
  • Like
Reactions: eult
Author
Sovde
Downloads
333
Views
432
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Sovde