1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Timespan to format

Discussion in 'Skript' started by Jordan, Apr 30, 2018.

Thread Status:
Not open for further replies.
  1. J

    Jordan Member

    Joined:
    Jan 25, 2017
    Messages:
    186
    Likes Received:
    12
    Hello,

    Mans was never the best at the old mathEMATICS at school so he is stuck on problem.

    How does one convert X seconds into a nicely formatted Days, Hours, Minutes and seconds

    I get you can convert a timespan into ticks, days, hours. minutes, seconds ect. with SKstuff but only works when you convert a timespan into a single hour or minute.. This does not work

    Set {_test} to "86400 Seconds" parsed as timespan to converted days, hours, minutes and seconds

    Just returns 1 day, 1 hour, 1 minute, 1 second

    I read up on integer division and some operator like % but then got confused and gave up :emoji_wink:

    Much help would be appreciated.

    I'm also aware you can display a timespan but it does not display Days, Hours, Minutes and seconds. all at once.

     
  2. Best Answer:
    Post #9 by Jordan, May 2, 2018
  3. JustADev

    JustADev Well-Known Member

    Joined:
    Apr 8, 2017
    Messages:
    380
    Likes Received:
    9
    Use @EWS's snippit for that,
    Code (Skript):
    1. function formatseconds(n: number) :: timespan:
    2.     set {_a} to "%{_n}% seconds" parsed as timespan
    3.     set {_a} to "%{_a}%"
    4.     replace all " seconds" or " second" with "sec" in {_a}
    5.     replace all " minutes" or " minute" with "min" in {_a}
    6.     replace all " hours" or " hour" with "h" in {_a}
    7.     replace all " days" or " day" with "d" in {_a}
    8.     return {_a}
     
  4. J

    Jordan Member

    Joined:
    Jan 25, 2017
    Messages:
    186
    Likes Received:
    12
    As i said in my post i already know about this, yet it's inconsistent very rarely displays the seconds and does not actually calculate times down to the decimals. Rounds down instead of up ect. This might be my skript version though if this is working for you i guess.
     
  5. JustADev

    JustADev Well-Known Member

    Joined:
    Apr 8, 2017
    Messages:
    380
    Likes Received:
    9
    usually, the "difference between {_Var} and now" will give you a precise answer, in decimals if that is what you are looking for
     
  6. J

    Jordan Member

    Joined:
    Jan 25, 2017
    Messages:
    186
    Likes Received:
    12
    Yeah but timespan will only display Hours and minutes. It'll display excess days and hours as decimals but is not accurate
     
  7. JustADev

    JustADev Well-Known Member

    Joined:
    Apr 8, 2017
    Messages:
    380
    Likes Received:
    9
    What do you mean "not accurate", like meaning that the timespans are rounded to a certain place? or what?
     
  8. J

    Jordan Member

    Joined:
    Jan 25, 2017
    Messages:
    186
    Likes Received:
    12
    When i ran test it was a couple seconds behind and again timespans only show hours and minutes which is not ideal.
     
  9. Snow-Pyon

    Moderator Resource Staff

    Joined:
    Jan 25, 2017
    Messages:
    1,233
    Likes Received:
    172
    Medals:
    There is really simple solution for this:
    Code (Skript):
    1. set {_test} to "1200 ticks" parsed as timespan
     
  10. J

    Jordan Member

    Joined:
    Jan 25, 2017
    Messages:
    186
    Likes Received:
    12
    What version of skript do you use? because timespan is only displayed as hours and minutes in mine?
    --- Double Post Merged, May 2, 2018, Original Post Date: May 2, 2018 ---
    Turns out skstuff's convert methods are broken, or some shit to do with timespans being broken as this should work i think?

    command /testtime:
    trigger:
    set {test} to "86460 seconds" parsed as timespan
    set {_GetDays} to {test} converted to days
    Set {_GetMinutes} to "%{_GetDays}%" parsed as timespan converted to minutes
    remove "%{_GetDays}% days" parsed as timespan from {_GetMinutes}
    broadcast "Days %{_GetDays}%, Minutes %{_GetMinutes}%"

    However just returns an internal error in chat and a bunch of errors in console to do with skstuff.
     
Thread Status:
Not open for further replies.
Loading...