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

1k views Asked by At

So in the game World of Warcraft I have managed to get the remaining time of a mission via their API. The problem for me is that I want to convert this to seconds to then be able to check at which time the mission will finish. If I call the function time() in the game I get a response similar to this 1418569973 which to me, makes no sense. But this is why I need to convert it to seconds, because then I can simply add the amount of seconds I get to the current time and get the end time of the mission.

But my problem is that the when I look into the table that gives me the current time left of a mission it returns a string with the format "X h X min" for example "4 h 34 min". I need to convert that to seconds but I literally have no idea on where to start. I'm thinking of something like removing the "h" and the "min" in a function. But from there I'm not really sure of where to go.

1

There are 1 answers

2
hjpotter92 On BEST ANSWER

os.time() returns the seconds since epoch. Thus, "1418569973" gives you "12/14/14 03:12:53 PM" UTC. Now, to convert your string to seconds:

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