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 out 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 Get seconds in timespan

Discussion in 'Skript' started by CommandActor, Sep 11, 2021.

Tags:
Thread Status:
Not open for further replies.
  1. CommandActor

    CommandActor Member

    Joined:
    Mar 3, 2018
    Messages:
    1
    Likes Received:
    0
    Hi.
    I'm trying to get the seconds in a variable containing a timespan object.

    Code (Text):
    1. set {_tdiff} to difference between now and {_start time}
    2. set {_seconds} to seconds in {_tdiff}
    The syntax above does not seem to work, I tried other expressions as well, like
    Code (Text):
    1. set {_seconds} to {_tdiff} converted to seconds
    and
    Code (Text):
    1. set {_seconds} to {_tdiff} parsed as number
    but they don't work.

    Could someone help me out please?

     
  2. Best Answer:
    Post #3 by Tenfont, Sep 11, 2021
  3. barrybtw

    barrybtw Active Member

    Joined:
    Jun 8, 2021
    Messages:
    82
    Likes Received:
    6
    You would need skript-reflect
    Code (Text):
    1.  
    2. set {_seconds} to {_tdiff}.getTicks() / 20
    3.  
     
  4. Tenfont

    Tenfont Member

    Joined:
    Mar 28, 2021
    Messages:
    24
    Likes Received:
    2
    You could use the method above, but you could also do this with vanilla using unix timestamps. Which method you use is up to you:

    Code (Text):
    1. set {_t1} to unix timestamp of ({timespan1} ago)
    2. set {_t2} to unix timestamp of ({timespan2} ago)
    3. set {_seconds} to difference of {_t1} and {_t2}
    4. # {_seconds} is the difference between {timespan1} and {timespan2} in seconds
     
    • Winner Winner x 1
Thread Status:
Not open for further replies.

Share This Page

Loading...