#Major . Posted August 16, 2021 Share Posted August 16, 2021 (edited) hello im working in a new script and i need help in 1 thing im trying to convert the string to time like ban Player 10m i want to convert that 10m to time and 10h 10sec etc. i didnt know how i can do it and split the numbers from the litters so i can know its hours or minutes etc Edited August 16, 2021 by #Major . Link to comment
nikitafloy Posted August 16, 2021 Share Posted August 16, 2021 (edited) local times = {['10m'] = 10 * 60000, ['1h'] = 60 * 60000} -- print(times['10m']) local timeUnits = {['m'] = 60000} -- 10m local number = string.match('10m', '%d+') local unit = string.match('10m', '%a+') -- print(tonumber(number) * timeUnits[unit]) Edited August 16, 2021 by nikitafloy Link to comment
Rockyz Posted August 16, 2021 Share Posted August 16, 2021 function stringToMS(str) local ms = 0 str = str:lower(); ms = ms + tonumber(str:match("(%d+)%s*s") or "0") * 1000 -- Seconds ms = ms + tonumber(str:match("(%d+)%s*m") or "0") * (1000 * 60) -- Minutes ms = ms + tonumber(str:match("(%d+)%s*h") or "0") * (1000 * 60 * 60) -- Hours ms = ms + tonumber(str:match("(%d+)%s*d") or "0") * (1000 * 60 * 60 * 24) -- Days ms = ms + tonumber(str:match("(%d+)%s*y") or "0") * (1000 * 60 * 60 * 24 * 365) -- Years return ms end 1 Link to comment
#Major . Posted August 16, 2021 Author Share Posted August 16, 2021 7 hours ago, RocKyz said: function stringToMS(str) 8 hours ago, nikitafloy said: local times = {['10m'] = 10 * 60000, ['1h'] = 60 * 60000} Thx for u it work Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now