Solved Better looking timespan

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Farid

Active Member
Feb 5, 2017
179
11
18
23
So I want timespan to be display as Hh:Mm:Ss

set {timespan} to now


send "%difference between now and {timespan}%"

would show (For example): 1 minutes and 3 seconds.

would like to display it like: 00:01:03 instead of 1 minutes and 3 seconds.
 
Alright here's my code, I never done any time related stuff, so it's gonna look messy probably :/

code_language.skript:
on skript load:
    set {restart::timer} to now formatted human-readable
    
every 1 second:
    set {_diff} to difference between {restart::timer} and now
    if {_diff} is 1 hour:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c3 HOURS.&e&l'"
    else if {_diff} is 2 hour:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c2 HOURS.&e&l'"
    else if {_diff} is 3 hours:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c1 HOUR.&e&l'"
    else if {_diff} is 3 hours and 55 minutes:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c5 MINUTES.&e&l'"
    else if {_diff} is 3 hours and 57 minutes:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c3 MINUTES..&e&l'"
    else if {_diff} is 3 hours and 58 minutes:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c2 MINUTE.&e&l'"
    else if {_diff} is 3 hours and 59 minutes:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c1 MINUTE.&e&l'"
    else if {_diff} is 3 hours and 59 minutes and 30 seconds:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c30 SECONDS.&e&l'"
    else if {_diff} is 3 hours and 59 minutes and 50 seconds:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c10 SECOND.&e&l'"
    else if {_diff} is 3 hours and 59 minutes and 57 seconds:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c3 SECOND.&e&l'"
    else if {_diff} is 3 hours and 59 minutes and 58 seconds:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c2 SECOND.&e&l'"
    else if {_diff} is 3 hours and 59 minutes and 59 seconds:
        broadcast "&4&l(!) &e&lSERVER RESTARTING IN '&c1 SECOND.&e&l'"
        execute console command "restart"
                
command /nextrestart:
    trigger:
        set {_time} to difference between {restart::timer} and now
        send "&e&l(!) &2Next Restart: &a&l%difference between 4 hours and {_time}%" to player
 
the formatted time expression returns a string not a timespan, use it when you want to broadcast the time not when youre setting the var
 
the formatted time expression returns a string not a timespan, use it when you want to broadcast the time not when youre setting the var
code_language.skript:
command /nextrestart:
    trigger:
        set {_time} to difference between {restart::timer} and now
        set {_now} to difference between 4 hours and {_time}
        send "&e&l(!) &2Next Restart: &a&l%{_now} formatted human-readable%" to player

returns none, but returns time when formatted human-readable is removed.
 
Last edited:
oops i forgot its for formatting dates not timespans
code_language.skript:
function getTimeString(time: timespan) :: string:
    set {_hours} to floor({_time}.getMilliSeconds() / 3600000)
    set {_minutes} to floor(mod({_time}.getMilliSeconds() / 60000, 60))
    set {_seconds} to floor(mod({_time}.getMilliSeconds() / 1000, 60))
    set {_hours} to "%{_hours}%" if {_hours} is greater than 9 else ("0%{_hours}%")
    set {_minutes} to "%{_minutes}%" if {_minutes} is greater than 9 else ("0%{_minutes}%")
    set {_seconds} to "%{_seconds}%" if {_seconds} is greater than 9 else ("0%{_seconds}%")
    return "%{_hours}%::%{_minutes}%::%{_seconds}%"
 
Status
Not open for further replies.