Skip to content

Show minutes/seconds #3396

Answered by vitoyucepi
gAlleb asked this question in Q&A
Sep 10, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @gAlleb,

You can create a function to convert unix time to a custom string pattern.
Consider this code

def format_time(time)
    int_time = int(time)
    seconds = int_time mod 60
    result = 
        if seconds < 10 then
            "0#{seconds}"
        else
            "#{seconds}"
        end
    minutes = int_time / 60
    result =
        if minutes < 10 then
            "0#{minutes}:#{result}"
        else
            "#{minutes}:#{result}"
        end
    result
end
   
print("#{format_time(116.7)} / #{format_time(184.3)}")
Alternatives
def format_time(time)
    seconds = int(time mod 60.)
    seconds_string =
        if seconds < 10 then
            "0" ^ string(seconds)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gAlleb
Comment options

Answer selected by gAlleb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants