Lua converts "X h X min" format to seconds in WoW

So in World of Warcraft I was able to get the remaining mission time through their API. The problem for me is that I want to convert this into a few seconds so that I can later check at what time the mission will end. If I call a function time()

in the game, I get a response like this 1418569973 which doesn't make sense to me. But this is why I need to convert it to seconds, because then I can just add the number of seconds I get at the current time and get the mission end time.

But my problem is that when I look at the table that gives me the current time to the left of the mission, it returns a string with the format "X h X min" like "4 h 34 min". I need to convert this in a few seconds, but I literally don't know where to start. I'm thinking of something like removing the "h" and "min" in a function. But from there I'm not really sure where to go.

+3


source to share


1 answer


os.time()

returns seconds since epoch . So "1418569973" gives you "12/14/14 03:12:53 PM" UTC . Now, to convert your string in seconds:



local iH, iM = sInput:match "(%d+) h (%d+) min"
iH, iM = tonumber( iH ), tonumber( iM )
local iSec = iH * 3600 + iM * 60

      

+4


source







All Articles